Autor Beitrag
jaenschi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 89

Win XP, Debian
D7
BeitragVerfasst: Do 24.02.05 18:50 
Hallo,
ich erstelle dynamisch ein formular und weise diesem auch einen dynamischen namen zu:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
with TForm.Create(Application) do
  begin
    name:=id;  
  end;

jetzt möchte ich, wenn ich so ein formular dynamisch erstellen lasse, auf diesem formular auch ein edit drauf haben.
Dafür muss ich dem edit als parent die variable id zuweisen. da diese aber ein string ist und er twincontrol erwartet, geht das nicht!
Gibt es eine möglichkeit einen string in twincontrol zu verwandeln oder wie könnte ich das sonst in den griff bekommen?
StefanH
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1144

Win XP
D5 Standard, D7 Pers, D2005 Pers
BeitragVerfasst: Do 24.02.05 19:39 
FindComponent wird dir helfen :)

_________________
"Als es noch keine Computer gab, war das Programmieren noch relativ einfach."(Edsger W. Dijkstra)
"Ich bin nicht von Sinnen, sondern ich rede wahre und vernünftige Worte." (Paulus)
jaenschi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 89

Win XP, Debian
D7
BeitragVerfasst: Do 24.02.05 19:44 
findcomponent liefert aber TComponent als rückgabewert und ich brauche ja TWinControl!
IngoD7
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 629


D7
BeitragVerfasst: Do 24.02.05 20:40 
I.)
Da du weißt, dass es ein Form sein wird, dass du über FindComponent findest, kannst du eine Typumwandlung machen:
MyEdit.Parent:=TWinControl(Application.FindComponent(id));Das funktioniert.

II.)
Du kannst aber auch dein Form als Variable deklarieren und dann normal benutzen. Siehe folgendes kleines Beispielprogramm:
ausblenden volle Höhe 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:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  MyForm : TForm;
  MyEdit : TEdit;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
MyForm := TForm.Create(Application);
MyForm.Name:=id;
MyForm.Visible:=true;
MyEdit := TEdit.Create(MyForm);
MyEdit.Parent:=MyForm;
end;

end.
jaenschi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 89

Win XP, Debian
D7
BeitragVerfasst: Do 24.02.05 20:57 
Das 1. funktioniert wunderbar! THX!!!
IngoD7
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 629


D7
BeitragVerfasst: Do 24.02.05 21:04 
jaenschi hat folgendes geschrieben:
Das 1. funktioniert wunderbar! THX!!!

Das 2. auch. :o :wink:
Bitte schön.