10. december 2002 - 02:05
Der er
6 kommentarer og 1 løsning
Simpelt spørgsmål om komponent
Jeg er igang med at lave en komponent i delphi. Denne kode linie virker, som den skal: Procedure GrayScale(Value: TImage); overload; Kan nogen fortælle mig hvorfor denne ikke virker: Procedure Resize(Value: TImage; Width: Integer; Height: Integer); Mangler der noget? Hvis der gør vil jeg blive glad, hvis der også er en forklaring med. På forhånd tak for svarene.
Annonceindlæg fra Infor
10. december 2002 - 21:43
#2
I får lige hele kilde-koden. _______________________________________________________________________________ unit Effect; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, JPEG, Dialogs, StdCtrls, Forms, extctrls, WinIoCtl; type TEffect = class(TComponent) private { Private declarations } protected { Protected declarations } public { Public declarations } Constructor Create(AOwner: TComponent); override; Destructor Destroy; override; published { Published declarations } Procedure GrayScale(Value: TImage); overload; Procedure Resize(Value: TImage; Width: Integer; Height: Integer); end; procedure Register; implementation procedure Register; begin RegisterComponents('PDJ', [TEffect]); end; constructor TEffect.Create(AOwner: TComponent); begin inherited Create(AOwner); end; destructor TEffect.Destroy; begin inherited Destroy; end; procedure TEffect.GrayScale(Value: TImage); var Gray, X, Y : Integer; PByte : PByteArray; begin with Value.Picture.Bitmap do begin for Y := 0 to Height -1 do begin PByte := ScanLine[Y]; for X := 0 to Width -1 do begin Gray := Round(PByte[X * 3] * 0.3 + PByte[X * 3 + 1] * 0.59 + PByte[X * 3 + 2] * 0.11); PByte[X * 3] := Gray; PByte[X * 3 + 1] := Gray; PByte[X * 3 + 2] := Gray; end; end; end; Value.Refresh; end; Procedure Resize(Value: TImage; Width: Integer; Height: Integer); var BitmapOriginal: TBitmap; BItmapNew : TBitmap; begin BitmapOriginal := TBitmap.Create; try BitmapOriginal.LoadFromFile(Value.Picture.Bitmap.GetNamePath); BitmapNew := TBitmap.Create; try BitmapNew.Width := Width; BitmapNew.Height := Height; BitmapNew.PixelFormat := pf24bit; BitmapNew.Canvas.StretchDraw( BitmapNew.Canvas.ClipRect, BitmapOriginal); Value.Picture.Graphic := BitmapNew finally BitmapNew.Free end finally BitmapOriginal.Free end end; end. _______________________________________________________________________________ Overload og override har jeg forsøgt mig med, uden held. Når jeg vil compile den for jeg følgende besked "Unsatisfied forward or external declaration".
11. december 2002 - 17:08
#5
Fordi der har du skrevet det rigtigt.Viser lige: Denne er rigtig procedure TEffect.GrayScale(Value: TImage); Denne er forkert Procedure Resize(Value: TImage; Width: Integer; Height: Integer); Denne er rigtig Procedure TEffect.Resize(Value: TImage; Width: Integer; Height: Integer);