Je suis sous W11 avec Delphi 6 Personal Edition.
J'essaie dans mon programme de créer plusieurs polices et d'affecter ces polices à différents contrôles VCL.
Je fais quelque chose comme ceci:
Dans mon esprit, cela crée 2 polices indépendantes, chacune paramétrée à un appel à FontDialog1.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 var Form2: TForm2; CellFont: TFont; MemoFont: TFont; implementation {$R *.dfm} procedure TForm2.FormCreate(Sender: TObject); begin CellFont := TFont.Create; MemoFont := TFont.Create; end; procedure TForm2.oFontSelectClick(Sender: TObject); begin FontDialog1.Font.Assign(CellFont); if not FontDialog1.Execute then exit; CellFont := FontDialog1.Font; end; procedure TForm2.oSelectFontMemoClick(Sender: TObject); begin FontDialog1.Font.Assign(MemoFont); if not FontDialog1.Execute then exit; MemoFont := FontDialog1.Font; end;
Je passe alors CellFont ou MemoFont en paramètre à une procédure.
Là, je veux l'affecter à ma police d'un objet VCL, comme ceci:
Or, à l'exécution, je reçois ceci:
Code : Sélectionner tout - Visualiser dans une fenêtre à part memo.Font.Assign(aFont);
Avant, à la place de Assign, j'affectais les propriétés Name, Size, Color et Style suivantes, comme ceci:
Ca marche pour le permier, mais dès que je veux affecter une autre police à un autre objet, TOUS les objets que j'ai utilisés prennent les attributs de la dernière police modifiée. C'est très frustrant.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 dest.Font.name = org.font.name ...
J'ai dû manquer un truc élémentaire... je pensais que Assign faisait le travail, selon https://docwiki.embarcadero.com/Libr...s.TFont.Assign:
Mais en exécution, le fait de passer ces Font en paramètre et de les utiliser dans une procédure, ça ne marche pas...Copies the properties of another TFont object.
Call Assign to set the properties of the font to match the characteristics of the Source object. If Source is another TFont object, Assign matches the font characteristics of the source. Assign does not copy the PixelsPerInch property, so this method can be used to copy a screen font to a printer font, or vice versa.
If the Source parameter is not another TFont object, Assign calls the inherited method so that the font can be copied from any object that can assign font properties in its AssignTo method.







Répondre avec citation



Partager