Ny begynder i Components....
Jeg er så småt begyndt at sysle med components - det går da også meget godt, indtil den skulle bruges - jeg troede bare det var at lave functioner/procedure og så kalde dem fra mit \"main program\" men efter at have læst lidt hist og her, har jeg fundt ud af jeg måske skal lave en event, for at starte procedure/eventen...Jeg ligger lige koden..
unit RegRW;
interface
uses WinTypes, WinProcs, Messages, SysUtils, Classes, Controls,
Forms, Graphics, Registry;
type
TWriteReadReg = class(TComponent)
private
{ Private fields of TWriteReadReg }
{ Storage for property RegKey }
FRegKey : String;
{ Storage for property RegPath }
FRegPath : String;
{ Storage for property RegRootPath }
FRegRootPath : HKEY;
{ Storage for property RegValue }
FRegValue : String;
{ Private methods of TWriteReadReg }
{ Method to set variable and property values and create objects }
procedure AutoInitialize;
{ Method to free any objects created by AutoInitialize }
procedure AutoDestroy;
protected
{ Protected fields of TWriteReadReg }
{ Protected methods of TWriteReadReg }
public
{ Public fields and properties of TWriteReadReg }
{ Public methods of TWriteReadReg }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
{ For reading keyvalue }
function RegRead : String;
{ For writing registry value to key }
procedure RegWrite;
published
{ Published properties of TWriteReadReg }
{ Key for read/writing }
property RegKey : String read FRegKey write FRegKey;
{ Path for key }
property RegPath : String read FRegPath write FRegPath;
{ Root Path }
property RegRootPath : HKEY read FRegRootPath write FRegRootPath;
{ Reg value }
property RegValue : String read FRegValue write FRegValue;
end;
procedure Register;
implementation
procedure Register;
begin
{ Register TWriteReadReg with Conatech as its
default page on the Delphi component palette }
RegisterComponents(\'Conatech\', [TWriteReadReg]);
end;
{ Method to set variable and property values and create objects }
procedure TWriteReadReg.AutoInitialize;
begin
FRegKey := \'TestKey\';
FRegPath := \'/Software/Conatech/test\';
FRegRootPath := HKEY_LOCAL_MACHINE;
FRegValue := \'Testvalue\';
end; { of AutoInitialize }
{ Method to free any objects created by AutoInitialize }
procedure TWriteReadReg.AutoDestroy;
begin
{ No objects from AutoInitialize to free }
end; { of AutoDestroy }
constructor TWriteReadReg.Create(AOwner: TComponent);
begin
{ Call the Create method of the parent class }
inherited Create(AOwner);
{ AutoInitialize sets the initial values of variables and }
{ properties; also, it creates objects for properties of }
{ standard Delphi object types (e.g., TFont, TTimer, }
{ TPicture) and for any variables marked as objects. }
{ AutoInitialize method is generated by Component Create. }
AutoInitialize;
{ Code to perform other tasks when the component is created }
end;
destructor TWriteReadReg.Destroy;
begin
{ AutoDestroy, which is generated by Component Create, frees any }
{ objects created by AutoInitialize. }
AutoDestroy;
{ Here, free any other dynamic objects that the component methods }
{ created but have not yet freed. Also perform any other clean-up }
{ operations needed before the component is destroyed. }
{ Last, free the component by calling the Destroy method of the }
{ parent class. }
inherited Destroy;
end;
{ For reading keyvalue }
function TWriteReadReg.RegRead : String;
var
Registry : TRegistry;
begin
Registry := TRegistry.Create;
Registry.RootKey := RegRootPath;
try
if Registry.OpenKey(RegPath, False) then
begin
Result := Registry.ReadString(RegKey);
end
finally
Registry.Free;
end;
end;
{ For writing registry value to key }
procedure TWriteReadReg.RegWrite;
var
Registry : TRegistry;
begin
Registry := TRegistry.Create;
Registry.RootKey := RegRootPath;
try
if Registry.OpenKey(RegPath, True) then
begin
Registry.WriteString(RegKey, RegValue);
end
finally
Registry.Free;
end;
end;
end.
Jeg troede så bare jeg kunne
WriteReadReg1.RegWrite
Fra mit program, men den går ikke, nogen der vil forklare lidt ?
