TColor to String (gelöst) ready to delete.

Für alles, was in den übrigen Lazarusthemen keinen Platz, aber mit Lazarus zutun hat.
Antworten
Maik81ftl
Beiträge: 619
Registriert: Mi 9. Mär 2011, 16:34
OS, Lazarus, FPC: Ubuntu10.04 LTS (L 0.9.31.0 FPC 2.4.4)
CPU-Target: 64Bit
Wohnort: seit 01.06.2011 in Wahlstedt

TColor to String (gelöst) ready to delete.

Beitrag von Maik81ftl »

Moin Moin,

Kann man mit einer Function den Wert einer Farbe (z.B. #C19757) in einen String umwandeln oder ist das schon in einer gewissen art ein String?

lg Maik81ftl

Edit!:

habe die function ColorToString gefungen,

verarbeite die werte nun wie folgt.

Code: Alles auswählen

procedure TForm3.Button1Click(Sender: TObject);
begin
     Settings.add(ColorToString(ProgSet.Menst));
     Settings.add(ColorToString(ProgSet.Stark));
     Settings.add(ColorToString(ProgSet.Periode));
     Settings.add(Progset.Font);
     Settings.SaveToFile('settings');
end;
Set ihr ggf. den fehler, für die meldung

"Abstract method called.

Press OK to Ignore and risk data corruption.
Press Cancel to kil the Programm.
Zuletzt geändert von Maik81ftl am Sa 26. Mär 2011, 11:31, insgesamt 1-mal geändert.
Ubuntu 10.04 LTS ist meine Heimat. Lazarus ist meine Sprache :D und der Kreis Segeberg meine LIEBE :D

Benutzeravatar
theo
Beiträge: 10869
Registriert: Mo 11. Sep 2006, 19:01

Re: TColor to String

Beitrag von theo »

Bei definierten Farben (clred, clfuchsia....) geht das so:

ColorToString($FF00FF);

Sonst eher nicht.

Maik81ftl
Beiträge: 619
Registriert: Mi 9. Mär 2011, 16:34
OS, Lazarus, FPC: Ubuntu10.04 LTS (L 0.9.31.0 FPC 2.4.4)
CPU-Target: 64Bit
Wohnort: seit 01.06.2011 in Wahlstedt

Re: TColor to String

Beitrag von Maik81ftl »

theo hat geschrieben:Bei definierten Farben (clred, clfuchsia....) geht das so:

ColorToString($FF00FF);

Sonst eher nicht.
ergo wenn ich die farben über folgende Aufrufe zuweise,

Code: Alles auswählen

procedure TForm3.Label5Click(Sender: TObject);
begin
     if ColorDialog1.Execute then begin
        Label5.Font.Color:= ColorDialog1.Color;
        Progset.Menst:= Label5.Font.Color;
     end;
end;
 
procedure TForm3.Label6Click(Sender: TObject);
begin
     if ColorDialog1.Execute then begin
        Label6.Font.Color:= ColorDialog1.Color;
        Progset.Stark:= Label6.Font.Color;
     end;
end;
 
procedure TForm3.Label7Click(Sender: TObject);
begin
     if ColorDialog1.Execute then begin
        Label7.Font.Color:= ColorDialog1.Color;
        Progset.Periode:= Label7.Font.Color;
     end;
end;
und nachfolgend abspeichern will, werde ich immer diese Fehlermeldung erhalten?. des is arg bescheiden.

aba ich weiß, es gibt die mgl, werte innerhalb der anwendung zu speichern. weis jedoch nicht wie. :(
Ubuntu 10.04 LTS ist meine Heimat. Lazarus ist meine Sprache :D und der Kreis Segeberg meine LIEBE :D

Benutzeravatar
theo
Beiträge: 10869
Registriert: Mo 11. Sep 2006, 19:01

Re: TColor to String

Beitrag von theo »

Nee, ich habe geantwortet bevor ich dein Edit gesehen hab.

Das ist ein andrer Fehler, der aus deinem Code nicht ersichtlich wird.
Wahrsch. hast du "Settings" oder "ProgSet" als TStrings statt TStringList deklariert bzw. konstruiert.
Das sieht man aber bei deinem Snippet nicht.

Maik81ftl
Beiträge: 619
Registriert: Mi 9. Mär 2011, 16:34
OS, Lazarus, FPC: Ubuntu10.04 LTS (L 0.9.31.0 FPC 2.4.4)
CPU-Target: 64Bit
Wohnort: seit 01.06.2011 in Wahlstedt

Re: TColor to String

Beitrag von Maik81ftl »

Ausgelagert.zip
theo hat geschrieben:Nee, ich habe geantwortet bevor ich dein Edit gesehen hab.

Das ist ein andrer Fehler, der aus deinem Code nicht ersichtlich wird.
Wahrsch. hast du "Settings" oder "ProgSet" als TStrings statt TStringList deklariert bzw. konstruiert.
Das sieht man aber bei deinem Snippet nicht.
^^ ok!

da hab ich hier mal den Code dieser Komletten Unit.

Code: Alles auswählen

unit Unit3; 
 
{$mode objfpc}{$H+}
 
interface
 
uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  ExtCtrls, ComCtrls, StdCtrls;
 
type
 
  TProgset = Record
             Menst, Stark, Periode: TColor;
             Font: String;
  end;
 
  { TForm3 }
 
  TForm3 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    ColorDialog1: TColorDialog;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    FontDialog1: TFontDialog;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    PageControl1: TPageControl;
    Panel1: TPanel;
    Tab1: TTabSheet;
    Tab2: TTabSheet;
    Tab3: TTabSheet;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Label5Click(Sender: TObject);
    procedure Label6Click(Sender: TObject);
    procedure Label7Click(Sender: TObject);
    procedure Label8Click(Sender: TObject);
  private
    { private declarations }
    Settings: TStrings;
  public
    { public declarations }
    Progset: TProgset;
  end; 
 
var
  Form3: TForm3;
 
Const
     stdcolor : TProgset = (Menst: clred;
                            Stark: clBlue;
                            Periode: clGreen;
                            Font: 'default');
 
 
implementation
 
{ TForm3 }
 
//uses unit1;
 
procedure TForm3.FormCreate(Sender: TObject);
//var temp: Byte;
begin
     Settings:= TStrings.Create;
     if FileExists('settings') then
        begin
        Settings.loadfromfile('settings');
        caption:= inttostr(Settings.Count);
        end;
     Label1.Font.Name:= StdColor.Font;
     Label2.Font.Name:= StdColor.Font;
     Label3.Font.Name:= StdColor.Font;
     Label4.Font.Name:= StdColor.Font;
     Label5.Font.Color:= Stdcolor.Menst;
     Label5.Font.Name:= StdColor.Font;
     Label6.Font.Color:= StdColor.Stark;
     Label6.Font.Name:= StdColor.Font;
     Label7.Font.Color:= StdColor.Periode;
     Label7.Font.Name:= StdColor.Font;
     Label8.Font.Name:= StdColor.Font;
end;
 
procedure TForm3.Button1Click(Sender: TObject);
begin
     caption:= '1 ';
     Settings.add(ColorToString(ProgSet.Menst));
     caption:= caption + 'OK ';
     caption:= caption + '2 ';
     Settings.add(ColorToString(ProgSet.Stark));
     caption:= caption + 'OK ';
     caption:= caption + '3 ';
     Settings.add(ColorToString(ProgSet.Periode));
     caption:= caption + 'OK ';
     caption:= caption + '4 ';
     Settings.add(Progset.Font);
     caption:= caption + 'OK ';
     caption:= caption + '5 ';
     Settings.SaveToFile('settings');
     caption:= caption + 'OK ';
end;
 
procedure TForm3.Label5Click(Sender: TObject);
begin
     if ColorDialog1.Execute then begin
        Label5.Font.Color:= ColorDialog1.Color;
        Progset.Menst:= Label5.Font.Color;
     end;
end;
 
procedure TForm3.Label6Click(Sender: TObject);
begin
     if ColorDialog1.Execute then begin
        Label6.Font.Color:= ColorDialog1.Color;
        Progset.Stark:= Label6.Font.Color;
     end;
end;
 
procedure TForm3.Label7Click(Sender: TObject);
begin
     if ColorDialog1.Execute then begin
        Label7.Font.Color:= ColorDialog1.Color;
        Progset.Periode:= Label7.Font.Color;
     end;
end;
 
procedure TForm3.Label8Click(Sender: TObject);
begin
     if FontDialog1.Execute then begin
        Label8.Font.Name:= FontDialog1.Font.Name;
        Label8.Left:= Form3.Width div 2 - Label8.Width div 2;
        Progset.Font:= Label8.Font.Name;
     end;
     Label1.Font.Name:= Progset.Font;
     Label2.Font.Name:= Progset.Font;
     Label3.Font.Name:= Progset.Font;
     Label4.Font.Name:= Progset.Font;
     Label5.Font.Name:= Progset.Font;
     Label6.Font.Name:= Progset.Font;
     Label7.Font.Name:= Progset.Font;
end;
 
initialization
  {$I unit3.lrs}
 
end.
für die, die nicht so viel hier lesen wollen, mach i noch ein zip ready.
Ubuntu 10.04 LTS ist meine Heimat. Lazarus ist meine Sprache :D und der Kreis Segeberg meine LIEBE :D

Benutzeravatar
theo
Beiträge: 10869
Registriert: Mo 11. Sep 2006, 19:01

Re: TColor to String

Beitrag von theo »

Da steht ja schon, was ich sagte. (Siehst du das nicht selber?)

Settings:= TStrings.Create;

müsste heissen:

Settings:= TStringList.Create;

Maik81ftl
Beiträge: 619
Registriert: Mi 9. Mär 2011, 16:34
OS, Lazarus, FPC: Ubuntu10.04 LTS (L 0.9.31.0 FPC 2.4.4)
CPU-Target: 64Bit
Wohnort: seit 01.06.2011 in Wahlstedt

Re: TColor to String

Beitrag von Maik81ftl »

theo hat geschrieben:Da steht ja schon, was ich sagte. (Siehst du das nicht selber?)

Settings:= TStrings.Create;

müsste heissen:

Settings:= TStringList.Create;
Das der kleine unterschied so eine wirkung hat. :mrgreen: :mrgreen:

Merde.
Ubuntu 10.04 LTS ist meine Heimat. Lazarus ist meine Sprache :D und der Kreis Segeberg meine LIEBE :D

Antworten