_ParentCtrl := Parent.Controls[0].Name;
... protected procedure SetParent(AParent: TWinControl); override; ...
procedure TQuest.SetParent(AParent: TWinControl); begin inherited SetParent(AParent); _ParentCtrl := AParent.Name; end;
procedure TQuest.SetParent(AParent: TWinControl); begin inherited; if Assigned(AParent) then Caption := aParent.Name; end;
procedure TQuest.SetParent(AParent: TWinControl); begin inherited SetParent(AParent); if Assigned(AParent) then // ici ta procédure qui utilise le Parent end;
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionMais dès que j'utilise ces propriétés dans le create ça plante
procedure TQuest.SetParent(Val : TWinControl); begin inherited SetParent(Val); if Assigned(Val) then begin showmessage(Val.Name+' => '+ inttostr(val.Width)+' x '+inttostr(Val.Height)); // tes calculs en fonction du Parent end. end;
aQuest := TQuest.Create(Self); // <-- appel du constructeur aQuest.Parent := Form1; // le Parent est toujours définit après le OnCreateil y a un ordre d'appel et de ce fait il est impossible d'utiliser le Parent dans le OnCreate.
TQuest = class(TWinControl) private FZoomState: TZoomState; procedure SetZoomState(aValue: TZoomState); published property ZoomState: TZoomState read FZoomState write SetZoomState; end; procedure TQuest.SetZoomState(aValue: TZoomState); begin if aValue <> FZoomState then begin FZoomState := aValue; Invalidate; // ici le composant est redessiné end; end;
protected procedure Paint; override; procedure TQuest.Paint; begin inherited Paint; Caption := Parent.Name; // <- test end;
Constructor TQuest.Create(AOwner: TComponent; AParent: TWidgetControl);
TQuest = class(TEdit) protected procedure SetParent(AParent: TWinControl); override; end; implementation { TQuest } procedure TQuest.SetParent(AParent: TWinControl); begin inherited SetParent(AParent); if Assigned(AParent) then Caption := aParent.Name; end;
procedure TfrmNumPad.FormCreate(Sender: TObject); begin with TQuest.Create(Self) do Parent := TabSheet2; end;
@korgis:
je comprends pas bien où tu fais une erreur ... j'ai testé le code et il fonctionne parfaitement !!!
Constructor TQuest.Create(AOwner : TComponent); Begin inherited Create(AOwner); inherited Width := 200; inherited Height:= 300; if (csDesigning in ComponentState) then SetParent(f_ParentOf(AOwner)); ... end;
Function TQuest.f_ParentOf(AChildren : TComponent): TWinControl; Var ii : integer; Begin Result := AChildren as TWinControl; // Par defaut For ii := 0 to AChildren.ComponentCount - 1 do begin if AChildren.Components[ii] Is TQuest then begin try Result := TQuest(AChildren.Components[ii]).Parent; if not Assigned(result) then begin showmessage('Non assigné'); Exit; end; Except end; end; end; End;
procedure TQuest.SetParent(Val : TWinControl); begin inherited SetParent(Val); showmessage(Val.Name+' => '+ inttostr(val.Width)+' x '+inttostr(Val.Height)); end;
Procedure TQuest.Paint; Begin inherited paint; if (csDesigning in ComponentState)then showmessage(Parent.Name+' => '+ inttostr(Parent.Width)+' x '+inttostr(Parent.Height));
procedure TQuest.SetParent(Val : TWinControl); begin inherited SetParent(Val); if Assigned(Val) and (csDesigning in ComponentState) and not (csLoading in ComponentState) and not (csReading in ComponentState) then begin showmessage(Val.Name+' => '+ inttostr(val.Width)+' x '+inttostr(Val.Height)); end; end;