Autor Beitrag
D. Annies
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Do 07.02.13 18:16 
Hi, Delpher,

wie kann man den folgenden (Spaghetti-)Code verbessern?

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:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
procedure TBuchMain.FontDialog1Click(Sender: TObject);
begin
  FontDialogAllg(TControl(TPopupMenu(TMenuItem(sender).GetParentComponent).popupComponent));
end;
procedure TBuchMain.FontDialog2Click(Sender: TObject);
begin
  FontDialogAllg(TControl(TPopupMenu(TMenuItem(sender).GetParentComponent).popupComponent));
end;
procedure TBuchMain.Fontdialog3Click(Sender: TObject);
begin
  FontDialogAllg(TControl(TPopupMenu(TMenuItem(sender).GetParentComponent).popupComponent));
end;
procedure TBuchMain.Fontdialog4Click(Sender: TObject);
begin
  FontDialogAllg(TControl(TPopupMenu(TMenuItem(sender).GetParentComponent).popupComponent));
end;
procedure TBuchMain.Fontdialog5Click(Sender: TObject);
begin
  FontDialogAllg(TControl(TPopupMenu(TMenuItem(sender).GetParentComponent).popupComponent));
end;
procedure TBuchMain.Fontdialog6Click(Sender: TObject);
begin
  FontDialogAllg(TControl(TPopupMenu(TMenuItem(sender).GetParentComponent).popupComponent));
end;
procedure TBuchMain.Fontdialog7Click(Sender: TObject);
begin
  FontDialogAllg(TControl(TPopupMenu(TMenuItem(sender).GetParentComponent).popupComponent));
end;
procedure TBuchMain.FontDialogAllg(Grid: TControl);
var tsg: TStringGrid;
    dbg: TDBGrid;
begin
  if (grid is TtntStringGrid) then
  begin
    tsg := (grid as TTntStringGrid);
    showmessage('Der Font kann mit dem Fontdialog geändert werden' +#13+
                ' (eingestellt ist zurzeit: '+
                    tsg.Font.Name+ ', '+ inttostr(tsg.font.size)+ ' )');
    if Tsg.rowcount > 1 then
    begin
      if buchDM_Dlg.fontdialog1.execute then
      begin
        tsg.Font := buchDM_Dlg.fontdialog1.Font;
        tsg.Canvas.Font := buchDM_Dlg.fontdialog1.Font;
      end;
    end;
    gridbreite(tsg, Groupbox4.Width, tsg.Font.Size);   //groupbox2.Width-Splitter2.MinSize);
  end;
  if (grid is TDBGrid) then
  begin
    dbg := (grid as TDBGrid);
    showmessage('Der Font kann mit dem Fontdialog geändert werden' +#13+
                ' (eingestellt ist zurzeit: '+
                    dbg.Font.Name+ ', '+ inttostr(dbg.font.size)+ ' )');

    if dbg.DataSource.DataSet <> NIL then
    begin
      if buchDM_Dlg.fontdialog1.execute then
      begin
        dbg.Font := buchDM_Dlg.fontdialog1.Font;
        dbg.Canvas.Font := buchDM_Dlg.fontdialog1.Font;
      end;
    end;
    dbgridbreite(dbg, Groupbox4.Width, dbg.font.size);    // groupbox2.Width-Splitter2.MinSize);
  end;
end;


Danke für eine Idee,
Detlef

_________________
ut vires desint, tamen est laudanda voluntas
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Do 07.02.13 18:51 
Hallo,

mir ist nicht ganz klar, was du meinst, aber warum die vielen FontDialogXClick-methoden?
du kannst doch allen Fontdialogs die gleiche Ereignis-behandlungsmethode zuweisen, brauchst doch nur eine.

Gruß Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)

Für diesen Beitrag haben gedankt: D. Annies
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Do 07.02.13 19:47 
Hi, Frank, du alter Delphi-Suchti!

Wir kennen uns ja nun auch schon etwas länger aus der Delphi-Hilfe.
Tja, das war natürlich die zündende Idee.

Danke, Detlef

_________________
ut vires desint, tamen est laudanda voluntas