Entwickler-Ecke

Sonstiges (Delphi) - Frage an Experten


Egbert - Di 13.04.04 14:16
Titel: Frage an Experten
In einer Druckerroutine möchte ich gern eine Abfrage einfügen, die mir sagt von welchem Formular aus der Aufruf erfolgt.

Folgendes Beispiel führte zu einem Fehler:


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
Procedure DruckeAdresse(IPCanvas : TCanvas;  Ed : TEdit;  LDR,DZ : integer);  
Var ZH:integer;
Begin
     IPCanvas.TextOut(LDR, DZ, Ed.Text);     
End;

Procedure DruckerAusgabe(IPCanvas:TCanvas; Grid1,Grid2:TStringGrid );
Var 
   Form : TForm;
   LDR, ZH : integer;     weitere Deklaration….
Begin
    If Grid1 = Form1.StringGrid1 then Form := Form1 else    // hier klappt noch alles
    If Grid1 = Form2.StringGrid1 then Form := Form2;          // hier klappt noch alles
    DruckeAdresse(IPCanvas, Form.Adr1, LDR, DZ);           // hier wird die TEdit --> Adr1 nicht erkannt.
End;


In Form1 und Form2 sind jeweils StringGrid1 und Adr1 usw. gleichermaßen deklariert.
Durch umständliche Abfragen habe ich zwar das Problem gelöst, möchte jedoch nach Möglichkeit eine einfachere bzw. elegantere Lösung verwenden.
………………………………………………………………………………………………………….
Hier meine umständliche, aber funktionierende Abfrage:

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:
38:
39:
40:
//--------------------------------------
Procedure DruAdrEd(IPCanvas:TCanvas; const Edit:TEdit; const LDR:integer;  var DZ:integer; 
                                    const FktZH, FktFo : double);      // Ausgabe auf Drucker oder Image
var ZH:integer;
Begin
    With IPCanvas do
    Begin
      Font:=Edit.Font;
      SetFontAusgl(IPCanvas, Edit.Font,FktFo);   // Fontangleichungsroutine f.Dru- / Image-Ausgabe
      Textout(LDR,DZ,Edit.Text);
      ZH:=TextHeight('Y');
      DZ:=DZ -Round(ZH*FktZH);  // Abstand zw.den Zeilen
    End;
End;
//---------------------------------------------
Procedure DruckeAdresse(IPCanvas,:TCanvas; Frm:Stringconst LDR:integer; var DZ:integer; 
                                             const FktZH, FktFo : double);
if Frm = ' Form1' then begin
  with Form1 do
  Begin
     if EdAdr1.Text<>'' then DruAdrEd(IPCanvas,EdAdr1,LDR,DZ,FktZH,FktFo); {Anrede}
     if EdAdr2.Text<>'' then DruAdrEd(IPCanvas,EdAdr2,LDR,DZ,FktZH,FktFo); {Vor/Zuname}
     usw...
  end;
end else begin
   if Frm = ' Form2' then
   with Form1 do
   Begin
      if EdAdr1.Text<>'' then DruckeAdrEd(IPCanvas,EdAdr1,LDR,DZ,FktZH,FktFo); {Anrede}
      if EdAdr2.Text<>'' then DruckeAdrEd(IPCanvas,EdAdr2,LDR,DZ,FktZH,FktFo); {V/Zname}
      usw...
   end;
end;
//------------------------------------------------
Abfrage in Haupt-Dru-Routine:
if Grid1 = Form1.StringGrid1  then Frm := 'Form1' else    
if Grid1 = Form2.StringGrid  then Frm := ' Form2';
DruckeAdresse( … );    
usw…
//----------------------------------------------

Wer kennt sich aus und hilft mir? Danke im voraus... Egb

Moderiert von user profile iconMotzi: Delphi-Tags hinzugefügt.


Anonymous - Di 13.04.04 15:01

Versuch mal statt Form.Adr1


Delphi-Quelltext
1:
TEdit(Form.FindComponent('Adr1'))                    


Egbert - Di 13.04.04 15:57

Vielen Dank für den hervorragenden Tipp. Klappt einwandfrei.

Habe aber da noch folgendes Problem.


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
  if Grid1 = Form1.StringGrid1  then 
  begin
     if Pos('Rechnung',Form1.EdAdr6.Text)>0 then RngFlg:=true;
     if Pos('Angebot', Form1.EdAdr6.Text)>0 then AngFlg:=true;
  end else
  if Grid1 = Form2.StringGrid1 then 
  begin
     if Pos('Rechnung',Form2.EdAdr6.Text)>0 then RngFlg:=true;
     if Pos('Angebot', Form2.EdAdr6.Text)>0 then AngFlg:=true;
  end;
  ReAngDru:= (RngFlg) or (AngFlg) or (FKoAnz=false);


wie sieht die Lösung in diesem Fall aus.

Moderiert von user profile iconMotzi: Delphi-Tags korrigiert.


Egbert - Di 13.04.04 19:40

Problem inzwischen gelöst. Nochmal Danke für die prompte Hilfe. Egb...