AGB  ·  Datenschutz  ·  Impressum  







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

Speicher-Fehler beim create

Ein Thema von Ykcim · begonnen am 26. Apr 2018 · letzter Beitrag vom 4. Mai 2018
Antwort Antwort
Alallart

Registriert seit: 8. Dez 2015
172 Beiträge
 
#1

AW: Speicher-Fehler beim create

  Alt 3. Mai 2018, 19:31
Weil ich gerade etwas Zeit habe, das mit Font.Styles etwas kompliziert ist, und ich zufällig ein fertiges Beispiel habe

Delphi-Quellcode:
uses
  IniFiles;

const
  //Wenn man für Sections und Idents Konstanten nimmt, schleichen sich später keine Fehler ein
  SecOptions = 'Options';
  IdFontName = 'FontName';
  IdFontSize = 'FontSize';
  IdFontStyle = 'FontStyle';
  SecInfo = 'Info';
  IdText1 = 'Text1';
  IdZahl1 = 'Zahl1';

procedure TForm1.Button1Click(Sender: TObject); //in eine Ini Daten speichern
var
  IniPath: String;
  IniFile: TIniFile;
  fsTemp: Byte;
  FontStyles: TFontStyles;
begin
  //Programmpfad als Grundlage für die Ini-Datei nehmen.
  IniPath := ChangeFileExt(ParamStr(0), '.ini');

  IniFile := TIniFile.Create(IniPath);
  try
    IniFile.WriteString(SecOptions, IdFontName, Canvas.Font.Name);
    IniFile.WriteInteger(SecOptions, IdFontSize, Canvas.Font.Size);
    FontStyles := Canvas.Font.Style; //Dieser Umweg für FontStyles ist nötig
    System.Move(FontStyles, fsTemp, 1); //FontStyles zum Byte-Wert konvertieren
    IniFile.WriteInteger(SecOptions, IdFontStyle, fsTemp);

    IniFile.WriteString(SecInfo, IdText1, 'Hallo Welt');
    IniFile.WriteInteger(SecInfo, IdZahl1, 42);
  finally
    IniFile.Free;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject); //aus einer Ini Daten landen
var
  IniPath: String;
  IniFile: TIniFile;
  fsTemp: Byte;
  FontStyles: TFontStyles;
  s: String;
  i: Integer;
begin
  //Programmpfad als Grundlage für die Ini-Datei nehmen.
  IniPath := ChangeFileExt(ParamStr(0), '.ini');

  IniFile := TIniFile.Create(IniPath);
  try
    Canvas.Font.Name := IniFile.ReadString(SecOptions, IdFontName, 'Arial'); //Arial=Defaultwert
    Canvas.Font.Size := IniFile.ReadInteger(SecOptions, IdFontSize, 10); //10=Defaultwert
    fsTemp := IniFile.ReadInteger(SecOptions, IdFontStyle, 0); //Dieser Umweg ist nötig
    System.Move(fsTemp, FontStyles, 1); //SizeOf?
    Canvas.Font.Style := FontStyles;

    s := IniFile.ReadString(SecInfo, IdText1, 'Hier ein Ersatztext im Fall eines Fehlers eingeben');
    i := IniFile.ReadInteger(SecInfo, IdZahl1, -1); //-1 ist der Ersatzwert im Fall eines Fehlers

    ShowMessage(Format('Der Text ist: "%s"; Die Zahl ist: %d', [s, i]));
  finally
    IniFile.Free;
  end;
end;
  Mit Zitat antworten Zitat
Ykcim

Registriert seit: 29. Dez 2006
Ort: NRW
856 Beiträge
 
Delphi 12 Athens
 
#2

AW: Speicher-Fehler beim create

  Alt 4. Mai 2018, 14:03
Vielen Dank!

Ich werde es mir vornehmen und versuchen, es nachzuvollziehen!

Besten Gruß!
Patrick
Patrick
  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 08:51 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz