Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Mit array of Txy auf anderes TForm zugreifen (https://www.delphipraxis.net/69955-mit-array-txy-auf-anderes-tform-zugreifen.html)

Martin.Ghosts 22. Mai 2006 21:30


Mit array of Txy auf anderes TForm zugreifen
 
Hallo,
ich habe ein kleines Problem und währe sehr dankbar, wenn mir jemand weiterhelfen könnte. Ich will z.B. mit array of TEdit auf ein anderes Formular zugreifen. Hier der Quelltext (leicht gekürzt):
Delphi-Quellcode:
var a: array [1..5] of TEdit;  ///globale Variable

TForm2.FormCreate;
var i: Integer;
begin
  for i:= 1 to 5 do
    begin
      a[i]:=Form1.Edit[i]  ///mit Edit[i] ist das glaub ich nicht richtig
    end;
end;
Die Frage ist jetzt, wie man das ganze umsetzen kann. Ich bekomme es irgendwie nicht hin. Vielen Dank für jegliche Hilfe,
Martin.Ghosts

mkinzler 22. Mai 2006 21:37

Re: Mit array of Txy auf anderes TForm zugreifen
 
Die Edits auf Form1 heißen EDIT1, Edit2, ...?
Dann geht das mit FindComponent.

Martin.Ghosts 22. Mai 2006 22:02

Re: Mit array of Txy auf anderes TForm zugreifen
 
Jetzt kapier ich Delphi nicht mehr. Ich habe es jetzt wie folgt umgesetzt:
Delphi-Quellcode:
var
  Form4: TForm4;
  edi: array [1..24] of TEdit;
  mem: array [1..8] of TMemo;

implementation

uses Unit3;

{$R *.dfm}

procedure TForm4.FormCreate(Sender: TObject);
var countedi, countmem: Integer;
begin
  for countedi:= 1 to 24 do
    begin
      edi[countedi]:= TEdit(Form3.FindComponent(IntToStr(countedi)));
      showmessage('HI');                                 /////////hier wirds interessant(siehe unten)
    end;
  for countmem:= 1 to 8 do
    begin
      mem[countmem]:= TMemo(Form3.FindComponent(IntToStr(countmem)));
    end;
end;
Jetzt kommt das für mich unerklärliche: Beim Staten des Programms wird jetzt 24 mal die Showmessage('HI') aufgerufen, das hat doch aber nichts mit dem Formular 4 zu tun. Es ist doch noch gar nicht erstellt. Oder werden beim Start des Programms schon alle Forms erstellt?

Phistev 22. Mai 2006 22:12

Re: Mit array of Txy auf anderes TForm zugreifen
 
Guck in den Projektoptionen nach, da steht, welche Formulare automatisch erstellt werden.

Martin.Ghosts 22. Mai 2006 22:47

Re: Mit array of Txy auf anderes TForm zugreifen
 
Gut, das klappt, vielen Dank. Aber das Programm funktioniert immer noch nicht so wie es soll. Ich habe das Programm mal folgendermaßen verändert:
Delphi-Quellcode:
procedure TForm4.FormCreate(Sender: TObject);
var i: Integer;
begin
  for i:= 1 to 5 do
    begin
      a[i]:= TEdit(Form3.FindComponent(IntToStr(i)));
      Form3.Edit1.Text:='test';
      showmessage(TEdit(Form3.FindComponent(IntToStr(i))));
    end;
end;
Die Showmessage hat aber kein Ergebniss, also verweist TEdit(Form3.FindComponent(IntToStr(i))) auch nicht auf Form3.Edit1.Text mit dem Inhalt 'test'. Der Fehler müsste ja in dem FindComponent Teil liegen.

Hawkeye219 22. Mai 2006 23:22

Re: Mit array of Txy auf anderes TForm zugreifen
 
Hallo,

versuche es einmal mit

Delphi-Quellcode:
FindComponent('Edit' + IntToStr(i));
Die ShowMessage-Zeile kann auch nicht funktionieren, denn ShowMessage erwartet einen String, keine Komponente. :wink:

Gruß Hawkeye

DP-Maintenance 23. Mai 2006 09:25

DP-Maintenance
 
Dieses Thema wurde von "sakura" von "XML" nach "VCL / WinForms / Controls" verschoben.
XML war wohl nicht die richtige Sparte, oder ;)

Martin.Ghosts 23. Mai 2006 14:24

Re: Mit array of Txy auf anderes TForm zugreifen
 
Danke, jetzt klappt alles :)

Martin.Ghosts


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:02 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz