AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Font-Attribute in INI-Datei speichern

Ein Thema von PeterPanino · begonnen am 18. Jul 2006 · letzter Beitrag vom 19. Jul 2006
Antwort Antwort
PeterPanino

Registriert seit: 4. Sep 2004
1.451 Beiträge
 
Delphi 10.4 Sydney
 
#1

Font-Attribute in INI-Datei speichern

  Alt 18. Jul 2006, 01:09
Hallo,

ich muss alle Attribute eines Font (Name, Size, Color usw.) in einer INI-Datei abspeichern. Gibt es dafür eine bequeme Komplettroutine oder muss ich jedes Font-Attribut einzeln abspeichern?

Vielen Dank im Voraus!
  Mit Zitat antworten Zitat
Benutzerbild von semo
semo

Registriert seit: 24. Apr 2004
755 Beiträge
 
Delphi 2010 Professional
 
#2

Re: Font-Attribute in INI-Datei speichern

  Alt 18. Jul 2006, 06:02
ich denke, dass du die alle einzeln abspeichern musst.
um nen bissl tipparbeit kommt man nun mal als programmierer nicht herum - und mal ehrlich - so viel arbeit ist das doch gar nicht.
  Mit Zitat antworten Zitat
v2afrank

Registriert seit: 9. Mai 2005
Ort: Bocholt
571 Beiträge
 
Delphi XE2 Professional
 
#3

Re: Font-Attribute in INI-Datei speichern

  Alt 18. Jul 2006, 06:10
Ich bin mir nicht mehr sicher wo ich die Routinen gefunden habe. Funktionieren aber
Delphi-Quellcode:
function FontToString(Font: TFont): String;
begin
  // name, size, bold, italic, underline, strikethrough, colour
  Result := Format('%s,%d,%d%d%d%d,%s', [Font.Name, Font.Size,
    Integer(fsBold in Font.Style), Integer(fsItalic in Font.Style),
      Integer(fsUnderline in Font.Style), Integer(fsStrikeOut in Font.Style),
      ColorToString(Font.Color)]);
end;

procedure StringToFont(Str: String; Font: TFont);
const
  SEP = ',';
  EXCEPT_MSG = 'Invalid string to font conversion';
var
  i: Integer;
begin
  {any exception/error we encounter will ultimately
  result in an EConvertError being raised}

  // name
  i := Pos(SEP, Str);
  if i = 0 then
    raise EConvertError.Create(EXCEPT_MSG);
  Font.Name := Copy(Str, 1, i - 1);
  Delete(Str, 1, i);

  // size
  i := Pos(SEP, Str);
  if i = 0 then
    raise EConvertError.Create(EXCEPT_MSG);
  Font.Size := StrToInt(Copy(Str, 1, i - 1));
  Delete(Str, 1, i);

  // bold, italic, underline, strikethrough
  if Pos(SEP, Str) <> 5 then
    raise EConvertError.Create(EXCEPT_MSG);
  Font.Style := [];
  if Str[1] = '1then
    Font.Style := Font.Style + [fsBold];
  if Str[2] = '1then
    Font.Style := Font.Style + [fsItalic];
  if Str[3] = '1then
    Font.Style := Font.Style + [fsUnderline];
  if Str[4] = '1then
    Font.Style := Font.Style + [fsStrikeOut];

  Delete(Str, 1, 5);

  // colour
  Font.Color := StringToColor(Str);
end;
  Mit Zitat antworten Zitat
marabu

Registriert seit: 6. Apr 2005
10.109 Beiträge
 
#4

Re: Font-Attribute in INI-Datei speichern

  Alt 18. Jul 2006, 06:46
Hier noch eine Alternative - nicht voll ausgebaut und nur um das Prinzip zu demonstrieren:

Delphi-Quellcode:
uses
  TypInfo,
  IniFiles;

procedure SaveToIniFile(o: TObject; ini: TMemIniFile; sectionName: String);
var
  i, iProps: integer;
  ppl: PPropList;
  ppi: PPropInfo;
begin
  ini.EraseSection(sectionName);
  iProps := GetPropList(o, ppl);
  for i := 0 to Pred(iProps) do
  begin
    ppi := ppl[i];
    case ppi.PropType^.Kind of
      tkString,
      tkLString:
        ini.WriteString(sectionName, ppi.Name, GetStrProp(o, ppi));
      tkInteger:
        ini.WriteString(sectionName, ppi.Name, IntToStr(GetOrdProp(o, ppi)));
      tkEnumeration:
        ini.WriteString(sectionName, ppi.Name, GetEnumProp(o, ppi));
      tkSet:
        ini.WriteString(sectionName, ppi.Name, GetSetProp(o, ppi));
      else
        ini.WriteString(sectionName, ppi.Name, '???');
    end;
  end;
end;

procedure TDemoForm.SaveButtonClick(Sender: TObject);
var
  fn: TFileName;
  ini: TMemIniFile;
begin
  fn := ChangeFileExt(ParamStr(0), '.ini');
  ini := TMemIniFile.Create(fn);
  SaveToIniFile(Font, ini, 'Font');
  ini.ReadSectionValues('Font', ValueListEditor.Strings);
  ini.UpdateFile;
  ini.Free;
end;
Grüße vom marabu
  Mit Zitat antworten Zitat
PeterPanino

Registriert seit: 4. Sep 2004
1.451 Beiträge
 
Delphi 10.4 Sydney
 
#5

Re: Font-Attribute in INI-Datei speichern

  Alt 19. Jul 2006, 02:21
Danke für die Hinweise - haben mir sehr geholfen!
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:07 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz