Autor Beitrag
Karlson
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 2088



BeitragVerfasst: Mo 19.03.07 00:32 
Moin,

Hab gerade das Problem, dass ich ca. 10 Forms habe, die alle über die gleiche Procedure aufgerufen können.

Ich schreibe mal Pseudocode, so sollte es am verständlichsten sein:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var dieforms: array[1..10] of TForm;

procedure test;
begin
 dieforms[1]:=Form2;
 dieforms[1].Show;
 dieForms[1].MeineProcedure;
end;


Natürlich sagt der Compiler "undeclared identifier 'MeineProcedure'".

Die "MeineProcedure" ist auf jeder der 10 Forms vorhanden (im Public deklariert), und ich wollte mich halt über das Array etwas an Tipparbeit sparen und den Code für die Bearbeitung einfach machen.

Kann mir jemand sagen wir ihr das macht? Klasse von Tform ableiten mit dieser Procedure?
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mo 19.03.07 01:11 
Du könntest die Formulare von einer gemeinsamen Vorfahrklasse ableiten:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
type
  TDoSomethingForm = class(TForm)
  public
    procedure DoSomething; virtual; abstract;
  end;

  TForm1 = class(TDoSomethingForm)
  public
    procedure DoSomething; override;
  end;

  var dieforms: array[1..10] of TDoSomethingForm ;

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Karlson Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 2088



BeitragVerfasst: Mo 19.03.07 22:10 
So hab ichs jetzt gemacht.

Dank Dir!