Clear code

0

jak uproscic taki kod :

    Chart1.RightAxis.LabelsFont.Color:=FontDialog.Font.Color;
    Chart1.TopAxis.LabelsFont.Color:=FontDialog.Font.Color;
    Chart1.BottomAxis.LabelsFont.Color:=FontDialog.Font.Color;
    Chart1.LeftAxis.LabelsFont.Color:=FontDialog.Font.Color;

    Chart4.RightAxis.LabelsFont.Color:=FontDialog.Font.Color;
    Chart4.TopAxis.LabelsFont.Color:=FontDialog.Font.Color;
    Chart4.BottomAxis.LabelsFont.Color:=FontDialog.Font.Color;
    Chart4.LeftAxis.LabelsFont.Color:=FontDialog.Font.Color;

    Chart1.RightAxis.LabelsFont.Name:=FontDialog.Font.Name;
    Chart1.TopAxis.LabelsFont.Name:=FontDialog.Font.Name;
    Chart1.BottomAxis.LabelsFont.Name:=FontDialog.Font.Name;
    Chart1.LeftAxis.LabelsFont.Name:=FontDialog.Font.Name;

    Chart4.RightAxis.LabelsFont.Name:=FontDialog.Font.Name;
    Chart4.TopAxis.LabelsFont.Name:=FontDialog.Font.Name;
    Chart4.BottomAxis.LabelsFont.Name:=FontDialog.Font.Name;
    Chart4.LeftAxis.LabelsFont.Name:=FontDialog.Font.Name;

    Chart1.RightAxis.LabelsFont.Style:=FontDialog.Font.Style;
    Chart1.TopAxis.LabelsFont.Style:=FontDialog.Font.Style;
    Chart1.BottomAxis.LabelsFont.Style:=FontDialog.Font.Style;
    Chart1.LeftAxis.LabelsFont.Style:=FontDialog.Font.Style;

    Chart4.RightAxis.LabelsFont.Style:=FontDialog.Font.Style;
    Chart4.TopAxis.LabelsFont.Style:=FontDialog.Font.Style;
    Chart4.BottomAxis.LabelsFont.Style:=FontDialog.Font.Style;
    Chart4.LeftAxis.LabelsFont.Style:=FontDialog.Font.Style;

</delphi>
0

Za wiele to go nie uprościsz, zamień Chart4 na Chart2 i możesz tak:

procedure Przypisz(var FontOsi: TFont; const FontDialog: TFontDialog);
begin
  FontOsi.Color := FontDialog.Font.Color;
   FontOsi.Name := FontDialog.Font.Name;
  FontOsi.Style := FontDialog.Font.Style;
end;

for n := 1 to 2 do
  with (FindComponent('Chart' + IntToStr(n)) as TChart) do
    begin
      Przypisz(RightAxis.LabelsFont, FontDialog);
      Przypisz(TopAxis.LabelsFont, FontDialog);
      Przypisz(BottomAxis.LabelsFont, FontDialog);
      Przypisz(LeftAxis.LabelsFont, FontDialog);
    end
0

procedure SetFont(var Fon: TTeeFont; const FontDialog: TFontDialog);
begin
Fon.Color := FontDialog.Font.Color;
Fon.name := FontDialog.Font.name;
Fon.Style := FontDialog.Font.Style;
end;

setfont(Chart1.RightAxis.LabelsFont,FontDialog.Font);

Error : Constant object cannot be passed as var parameter

Druga metoda :

function SetFont(Fon:TFont):TTeeFont;
var f:TTeeFont;
begin
f.Color := Fon.Color;
f.name := Fon.name;
f.Style := Fon.Style;
f.Size := Fon.Size;
result:=f;
end;

Chart1.RightAxis.LabelsFont:=setfont(FontDialog.Font);

Error - access :/

Czy da rade wykorzystac with ... do ... zeby przypisac kilku elementa ta sama wartosc ?
np.

with char1,char4 do
title:='aaaa';

0

mi zawsze działało coś w stylu u ciebie:

Chart1.RightAxis.LabelsFont:=FontDialog.Font;
Chart1.TopAxis.LabelsFont:=FontDialog.Font;
Chart1.BottomAxis.LabelsFont:=FontDialog.Font;
Chart1.LeftAxis.LabelsFont:=FontDialog.Font;

0
with Chart1 do
  begin
  RightAxis.LabelsFont.Assign(FontDialog.Font);
  TopAxis.LabelsFont.Assign(FontDialog.Font);
  BottomAxis.LabelsFont.Assign(FontDialog.Font);
  LeftAxis.LabelsFont.Assign(FontDialog.Font);
  end;

1 użytkowników online, w tym zalogowanych: 0, gości: 1