Thema: Delphi TColor in reg schreiben

Einzelnen Beitrag anzeigen

Chris92 .A

Registriert seit: 19. Mai 2010
56 Beiträge
 
#3

Re: TColor in reg schreiben

  Alt 24. Mai 2010, 11:52
Hmm irgendwie funktioniert das aber nicht. Hier ist mein Code. In einer Unit3 die für die Einstellungen des Pong Spiel gedacht ist wollte ich die Farbe der Schläger verändern. Die Unit2 ist das eigentliche Spiel wo sich die Schläger befinden.

Delphi-Quellcode:
unit Unit3;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,Registry;

type
  TfrmOption = class(TForm)
    Label1: TLabel;
    btnSpeichern: TButton;
    dlgColor: TColorDialog;
    Label2: TLabel;
    Label3: TLabel;
    btn1Color: TButton;
    btn2Color: TButton;
    Edit1: TEdit;
    procedure btn1ColorClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmOption: TfrmOption;
  reg: TRegistry;

implementation
uses unit2;

{$R *.DFM}
procedure TfrmOption.FormCreate(Sender: TObject);
begin
reg := TRegistry.Create;

end;
procedure TfrmOption.FormDestroy(Sender: TObject);
begin
        reg.Free;
end;

procedure TfrmOption.btn1ColorClick(Sender: TObject);
begin
        if dlgColor.execute then
                Leftcolor := dlgColor.color;

        if reg.OpenKey('Software\FDAC\Pong', true) then
        begin
                reg.WriteInteger('Leftcolor', Leftcolor);
                reg.CloseKey;
        end;
end;

end.
---------------------------------------

Delphi-Quellcode:
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls, Menus, MPlayer, ExtDlgs, jpeg,Unit3,Registry;

type
  TfrmPong = class(TForm)
    tmBall: TTimer;
    pnlLeft: TPanel;
    pnlLine: TPanel;
    lblLeftPoint: TLabel;
    lblRightPoint: TLabel;
    pnlRight: TPanel;
    mmMenu2: TMainMenu;
    mmiPause: TMenuItem;
    mmiSound: TMenuItem;
    dlgOpen: TOpenDialog;
    mpWM: TMediaPlayer;
    mmiWMLied: TMenuItem;
    dlgPicture: TOpenPictureDialog;
    imgBall: TImage;
    pnlBottom: TPanel;
    pnlTop: TPanel;
    mmicolor: TMenuItem;
    dlgcolor2: TColorDialog;
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure FormCreate(Sender: TObject);
    procedure FormClick(Sender: TObject);
    procedure tmBallTimer(Sender: TObject);
    procedure mmiPauseClick(Sender: TObject);
    procedure mmiWMLiedClick(Sender: TObject);
    procedure mmicolorClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmPong: TfrmPong;
  var X,Y,VX,VY:integer;
  var Test:Boolean;
  var FWidth,FHeight:Integer;
  var Leftcolor:integer;


implementation

{$R *.DFM}


procedure TfrmPong.FormCreate(Sender: TObject);
var
  reg: TRegistry;
begin
        reg := TRegistry.Create;
        if reg.OpenKey('Software\FDAC\Pong', false) then
        begin
                if reg.ValueExists('Leftcolor') then
                begin
                        pnlLeft.Color := reg.ReadInteger('Leftcolor');
                end;
        reg.CloseKey
        end;
        reg.Free;
end;
  Mit Zitat antworten Zitat