| Autor |
Beitrag |
JayK
      
Beiträge: 1013
|
Verfasst: Mi 23.03.05 12:53
Hallo Leute,
wie stellt man es an, dass z.B. eine Dialogbox, die ein TImage enthält, als neue Komponente eine property hat, mit der man die Picture-Property von der TImage ändern kann?
Also, dass man im Objektinspektor doppelt draufklickt und der Bildeditor kommt hervor.
Wenn ich das mit direkter Variablenzuweisung (Typ TPicture) mache schüttet Delphi mich mit Fehlermeldungen zu, und zwar immer beim Einfügen der Komponente und wenn man mit der Maus im Objektinspektor über die Property fährt.
Beim Testen bricht das Programm immer mit einem Laufzeitfehler ab, wenn ich auf die DlgBox zugreife.
Kann mir da einer helfen  : Moderiert von Tino: Topic aus Sonstiges verschoben am Mi 23.03.2005 um 14:53
|
|
wdbee
      
Beiträge: 628
Erhaltene Danke: 1
|
Verfasst: Mi 23.03.05 13:06
Statt TForm1 muss es deine Komponente sein:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24:
| type TForm1 = class(TForm) private oPicture: TPicture; procedure SetPicture(NewPicture: TPicture); public published property Picture: TPicture read oPicture write SetPicture; end;
var Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.SetPicture(NewPicture: TPicture); begin if oPicture <> NewPicture then oPicture.Assign(NewPicture); end; |
|
|
JayK 
      
Beiträge: 1013
|
Verfasst: Mi 23.03.05 13:14
Danke, nachdem ich zu Mittag gegessen habe werde ich es probieren. 
|
|
JayK 
      
Beiträge: 1013
|
Verfasst: Mi 23.03.05 14:38
Irgentwie klappt es immer noch nicht. Es kommen immer noch Fehlermeldungen im Design-Modus.
Ich kann ja mal den Text weitergeben, aber ich glaub irgentwie kaum das das was nützt:
| Zitat: | | Acces Violation at Adress 0035AD88 in module 'designide60.bpl'. Read of adress 0000000C. |
Am besten schicke ich mal den kompletten Code der Komponente:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79:
| unit JayAboutBox;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, About, JvComponent, JvBaseDlg, JvJVCLAboutForm, StdCtrls, JvExControls, JvStaticText, ExtCtrls, JvExExtCtrls, JvImage, JvPanel, JvGradientHeaderPanel; type TJayAboutBox = class(TCommonDialog) private FCaption, FProgramName, FCompanyName, FCopyrightMessage, FAuthor, FComments, FVersion, FButtonOkCaption, FButtonJVCLCaption : String; FShowJVCLButton : Boolean; oPicture: TPicture; procedure SetLargeicon(NewPicture: Tpicture); public function Execute: Boolean; published property Caption: String read FCaption write FCaption; property ProgramName: String read FProgramName write FProgramName; property CompanyName: String read FCompanyName write FCompanyName; property Copyright: String read FCopyrightMessage write FCopyrightMessage; property Author: String read FAuthor write FAuthor; property Comments: String read FComments write FComments; property Version: String read FVersion write FVersion; property ButtonOkCaption: String read FButtonOkCaption write FButtonOkCaption; property ButtonJVCLCaption: String read FButtonJVCLCaption write FButtonJVCLCaption; property ShowJVCLButton: Boolean read FShowJVCLButton write FShowJVCLButton default True; property LargeIcon: TPicture read oPicture write SetlargeIcon; end;
procedure Register;
implementation
procedure Register; begin RegisterComponents('Jakob', [TJayAboutBox]); end;
procedure TJayAboutbox.SetLargeicon(NewPicture: TPicture); begin if oPicture <> NewPicture then oPicture.Assign(NewPicture); end;
function TJayAboutBox.Execute: Boolean; begin AboutBox := TAboutBox.Create(Application); try try AboutBox.Caption := Caption; Aboutbox.ProductName.LabelCaption := ProgramName; AboutBox.Copyright.Caption := Copyright; AboutBox.Autor.Caption := Author; AboutBox.Comments.Caption := Comments; AboutBox.Version.Caption := Version; AboutBox.OKButton.Caption := ButtonOkCaption; AboutBox.JVCL.Caption := ButtonJVCLCaption; Aboutbox.JVCL.Visible := ShowJVCLButton; AboutBox.SmallProgramIcon.Picture.Icon := application.Icon; AboutBox.ProgramIcon.Picture := LargeIcon; case AboutBox.ShowModal of mrOK: Result := true; end; except Result := false; end; finally Aboutbox.Free; end; end;
end. |
Hoffentlich hilft das.
PS. Wenn sonst noch Verbesserungsvorschläge zum Syntax da sind, wäre ich auch froh drüber  ;
|
|
wdbee
      
Beiträge: 628
Erhaltene Danke: 1
|
Verfasst: Mi 23.03.05 14:42
Wo ist denn dein Constructor-Aufruf für oPicture? Das ist ein Objekt und muss im Constructor deiner Komponente erzeugt werden!
|
|
Tino
      

Beiträge: 9839
Erhaltene Danke: 45
Windows 8.1
Delphi XE4
|
Verfasst: Mi 23.03.05 14:53
Und bitte im Destruktor wieder freigeben. 
|
|
wdbee
      
Beiträge: 628
Erhaltene Danke: 1
|
Verfasst: Mi 23.03.05 15:01
@Tino: Vorsicht, wenn das Objekt in die Componentlist der Komponente aufgenommen wird (per Create(Owner=Komponente)), passiert das automatisch. Wenn er es selbst auch macht, gibt es das alte Problem!
|
|
Tino
      

Beiträge: 9839
Erhaltene Danke: 45
Windows 8.1
Delphi XE4
|
Verfasst: Mi 23.03.05 15:14
Wenn ich eine Komponente im Konstrukor erstelle dann gebe ich diese auch im Desturktor wieder frei. Damit habe ich bis jetzt nie ein Problem gehabt. Egal ob ich NIL oder die Komponente in der ich die Komponete erstelle als Owner angegeben habe.
|
|
JayK 
      
Beiträge: 1013
|
Verfasst: Mi 23.03.05 17:38
Tut mir wirklich leid, aber ich muss wohl erklären, dass ich ein totaler Delphi-Anfänger bin und erst seit ca. 4 Wochen etwas anständiges zu prgrammieren versuche.  (Also ich meine, dass ich davor nur Kinkerlitzchen und Kleinigkeiten mit Delphi gemacht, etwas streng nach Anleitung programmiert oder mir etwas dazu angelesen habe.)
Könntet ihr mir deswegen bitte etwas genauer erklären was ich da reinschreiben soll?
Vielen Dank, schon mal im voraus.
Also, ich soll für meine Komponente einen Contructor ertstellen und darin das Objekt oPicture (dynamisch  ) erstellen?
So richtig habe ich es nicht verstanden. 
|
|
wdbee
      
Beiträge: 628
Erhaltene Danke: 1
|
Verfasst: Mi 23.03.05 18:30
Wir meinen folgendes:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31:
| ... type TJayAboutBox = class(TCommonDialog) private FCaption, FProgramName, FCompanyName, FCopyrightMessage, FAuthor, FComments, FVersion, FButtonOkCaption, FButtonJVCLCaption : String; FShowJVCLButton : Boolean; oPicture: TPicture; procedure SetLargeicon(NewPicture: Tpicture); public constructor Create(AOwner: TComponent); override; destructor Destroy; override; function Execute: Boolean; published ...
implementation
... constructor TJayAboutBox.Create(AOwner: TComponent); begin inherited Create(AOwner); oPicture := TPicture.Create; end;
destructor TJayAboutBox.Destroy; begin oPicture.Free inherited Destroy; end; ... |
// Edit: Mein Fehler: TPicture ist kein TComponent, Sorry
Zuletzt bearbeitet von wdbee am Mi 23.03.05 18:58, insgesamt 1-mal bearbeitet
|
|
JayK 
      
Beiträge: 1013
|
Verfasst: Mi 23.03.05 18:54
Der Compiler meckert bei mir an zwei Stellen:
1. bei
oPicture := TPicture.Create(self);
mit der Meldung | Zitat: | | Too many actual parameters |
und
2. bei
oPicture.Parent := self; gleich dannach
mit der Meldung | Zitat: | | Undecleared Identifier: 'Parent' |
hab ich irgetwas vergessen?
|
|
wdbee
      
Beiträge: 628
Erhaltene Danke: 1
|
Verfasst: Mi 23.03.05 19:04
|
|
JayK 
      
Beiträge: 1013
|
Verfasst: Mi 23.03.05 19:10
Na dann bin ich (sind wir) ja wieder am Anfang... 
|
|
wdbee
      
Beiträge: 628
Erhaltene Danke: 1
|
Verfasst: Mi 23.03.05 19:14
Jetzt müssen deine Fehlermeldungen doch weg sein, denn die beiden Zeilen habe ich ja geändert!
|
|
JayK 
      
Beiträge: 1013
|
Verfasst: Mi 23.03.05 19:17
Ups... Stimmt! Die Änderung im Code hab ich gar nicht bemerkt  ! Dankeschön.
Mal sehen ob's jetze funzt...
|
|
JayK 
      
Beiträge: 1013
|
Verfasst: Mi 23.03.05 19:57
Juhu  ! Es klappt. Danke für eure Hilfe Leute!!
|
|