Autor Beitrag
Daniel L.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 140
Erhaltene Danke: 14

W7, W8
TurboD Prof, Delphi Community
BeitragVerfasst: Di 02.11.10 18:09 
Hi,

wie könne man eine zufälligen, gültigen Fontnamen erstellen?
ausblenden Delphi-Quelltext
1:
label1.font.name := GetRandomFontmame;  // z.B Tahoma					


Ich weiss, wie man mit random() umgeht, aber nicht, wie und wo ich die Fonts herkriege.

Vielen Dank + Gruss: Daniel
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Di 02.11.10 18:16 
AFAIR gibt es in Screen.Fonts eine Liste. Kann auch in einer anderen Klasse sein, aber irgendwo in der VCL gibt es eine solche Eigenschaft.

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
ALF
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1085
Erhaltene Danke: 53

WinXP, Win7, Win10
Delphi 7 Enterprise, XE
BeitragVerfasst: Di 02.11.10 18:18 
Jo, mein Vorschlag.
Du müsstest erst mal rausbekommen wieviele Fonts zu verfügung stehen! Also das FontArray durchsuchen. Hast Du diese Zahl, kannst Du sie zufällig generieren und dann das FontArray mit der gefundenen Zahl ansprechen. Mal so mein Gedanke.

Gruss ALf

_________________
Wenn jeder alles kann oder wüsste und keiner hätt' ne Frage mehr, omg, währe dieses Forum leer!
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Di 02.11.10 18:27 
Screen.Fonts ist eine Stringlist. Demnach müsste folgendes funktionieren:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
function GetRandomFontName(): String;
begin
  Result := Screen.Fonts[Random(Screen.Fonts.Count)];
end;


lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.


Zuletzt bearbeitet von elundril am Di 02.11.10 19:40, insgesamt 1-mal bearbeitet
Daniel L. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 140
Erhaltene Danke: 14

W7, W8
TurboD Prof, Delphi Community
BeitragVerfasst: Di 02.11.10 18:55 
sänks ä lott ! :D

edit:
ich glaube, ohne -1:
Result := Screen.Fonts[Random(Screen.Fonts.Count)];
Stundenplan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 128
Erhaltene Danke: 32

Win 7
Delphi 7 Pers., C# (VS 2010 Express)
BeitragVerfasst: Di 02.11.10 19:35 
Mit -1, denn Count ist nur die Anzahl der Arrayelemente, das Array geht aber von 0..Count-1, Beispiel:
Wenn ich ein Array habe, welches von 0 bis 3 geht, hab ich 4 Elemente, nämlich 0, 1, 2, und 3.
Und damit du nicht versuchst, auf ein Arrayelement zuzugreifen, welches gar nicht existiert (Beim Random(Count) könnte ja auch zufällig mal Count rauskommen, aber das Array geht ja nur bis Count-1), musst du eben entsprechend 1 abziehen.

Edit: Tatsächlich Ohne -1, siehe Gausis Post unten. :oops:

Viele Grüße,
Stundenplan.


Zuletzt bearbeitet von Stundenplan am Di 02.11.10 19:53, insgesamt 1-mal bearbeitet
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Di 02.11.10 19:37 
Ne, ohne -1, denn Random(x) liefert eine Zahl größer oder gleich 0 und echt kleiner x. ;-)

_________________
We are, we were and will not be.
Daniel L. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 140
Erhaltene Danke: 14

W7, W8
TurboD Prof, Delphi Community
BeitragVerfasst: Di 02.11.10 19:39 
ebend :wink2:
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Di 02.11.10 19:39 
oh, ich dachte kleiner gleich. sorry, ich verbessere es mal schnell.

lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 02.11.10 19:53 
user profile iconGausi hat folgendes geschrieben Zum zitierten Posting springen:
Ne, ohne -1, denn Random(x) liefert eine Zahl größer oder gleich 0 und echt kleiner x. ;-)

Oder anders gesagt: random(n) hat n mögliche Ausgaben, bei 0 beginnend.