Bonjour et bonne année,
Pour commencer voici un code qui marche:
Sauf que je voudrais faire Parent := Form1; dans le create
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm1 = class(TForm) Button1: TButton; Panel1: TPanel; procedure Button1Click(Sender: TObject); private { Déclarations privées } public { Déclarations publiques } end; Tmyclass = class(TPanel) Image: TImage; // Info:Double; private public constructor Create(AOwner: TComponent); destructor Destroy; end; var Form1: TForm1; Compo: Tmyclass; implementation {$R *.dfm} { Tmyclass } constructor Tmyclass.Create(AOwner: TComponent); begin inherited; Image := TImage.Create(nil); //parent:=AOwner; with Image do begin Parent := Self; Visible := True; end; end; destructor Tmyclass.Destroy; begin if Assigned(Image) then FreeAndNil(Image); inherited; end; procedure TForm1.Button1Click(Sender: TObject); begin Compo := Tmyclass.Create(Form1); with Compo do begin Parent := Form1; Compo.Image.Canvas.pen.Color:=clgreen; Compo.Image.Canvas.MoveTo(0,0); Compo.Image.Canvas.LineTo(10,10); end; end; end.
j'ai donc modifier celui-ci ainsi:
Seul souci, c'est que j'ai alors delphi qui me retourne le message:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 constructor Tmyclass.Create(AOwner: TComponent); begin inherited; Image := TImage.Create(nil); parent:=AOwner; with Image do begin Parent := Self; Visible := True; end; end;
Je me dis donc que j'ai qu'a prendre en paramettre un TwinControl. Mon code devient:[Erreur] Unit1.pas(42): Types incompatibles : 'TWinControl' et 'TComponent'
et la Delphi bloque sur le mot clef inherited; et me dit:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 constructor Tmyclass.Create(AOwner: TWinControl); begin inherited; Image := TImage.Create(nil); parent:=AOwner; with Image do begin Parent := Self; Visible := True; end; end;
Quelqu'un a une idée de comment résoudre ce dylème ?renvoie "[Erreur] Unit1.pas(40): Types incompatibles
Partager