Hola,
Hombre, con "la forma" me refería al archivo "dfm", que acompaña al "pas" y es donde se guardan los datos relativos a "la forma"... ¡has puesto un archivo "GIF"! Vamos, que así no se puede compilar...
Creo que faltaba únicamente lo que refiere
roman más arriba y lo que también yo he dicho: el que los métodos sean eso, métodos pertenecientes al formulario y no simples procedimientos; y los "end;" cerrando los bloques "finally". Así me ha quedado, pero, insisto, no he podido compilarlo, puesto que no se cuenta con el archivo "dfm" asociado...
Código Delphi
[-]
unit NGFS;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls, CPortCtl, CPort, Registry;
type
TForm1 = class(TForm)
BIn: TButton;
BOut: TButton;
GroupBox1: TGroupBox;
LCurrPos: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
BGoto: TButton;
LTotStep: TLabel;
BCali: TButton;
PBCurrPos: TProgressBar;
Timer1: TTimer;
ComComboBox1: TComComboBox;
ComPort1: TComPort;
ComLed1: TComLed;
Eminstep: TEdit;
Emaxstep: TEdit;
Label1: TLabel;
Eminstop: TEdit;
Label7: TLabel;
Emaxstop: TEdit;
BConnect: TButton;
EGoto: TEdit;
private
RegNGFS: TRegistry;
public
procedure ReadRegistry(MaxSteps: Integer; MinSteps: Integer;
StopOUT: Integer; StopIN: Integer; COMPort: String);
procedure WriteRegistry;
end;
var
Form1: TForm1;
MaxSteps: Cardinal; MinSteps: Cardinal; StopOUT: Cardinal; StopIN: Cardinal; COMPort: String;
implementation
{$R *.dfm}
procedure TForm1.ReadRegistry(MaxSteps: Integer; MinSteps: Integer;
StopOUT: Integer; StopIN: Integer; COMPort: String);
begin
RegNGFS:= TRegistry.Create;
try
RegNGFS.RootKey := HKEY_LOCAL_MACHINE;
if RegNGFS.OpenKey('SOFTWARE\NGFS', FALSE) then
begin
RegNGFS.ReadCardinal('MaxSteps');
MinSteps:= RegNGFS.ReadCardinal('MinSteps');
StopOUT:= RegNGFS.ReadCardinal('StopOUT');
StopIN:= RegNGFS.ReadCardinal('StopIN');
COMPort:= RegNGFS.ReadString('COMPort');
end;
finally
RegNGFS.Free;
end;
end;
procedure TForm1.WriteRegistry;
begin
RegNGFS:= TRegistry.Create;
try
RegNGFS.RootKey := HKEY_LOCAL_MACHINE;
if RegNGFS.OpenKey('SOFTWARE\NGFS', TRUE) then
begin
RegNGFS.WriteCardinal('MaxSteps', MaxSteps);
RegNGFS.WriteCardinal('MinSteps', MinSteps);
RegNGFS.WriteCardinal('StopOUT', StopOUT);
RegNGFS.WriteCardinal('StopIN', StopIN);
RegNGFS.WriteString('COMPort', COMPort);
end;
finally
RegNGFS.Free;
end;
end;
end.
Actualización: He atrasado fuera de los bloques "try ... finally" la instrucción encargada de crear la instancia de la clase "TRegistry". Creo que así es lo suyo, puesto que de otro modo tal vez en caso de error habría problemas: siempre se pasaría por el "finally", pero, ¿no sería posible que no se hubiera creado la instancia de "TRegistry"?. De este modo en principio se creará la instancia, luego se pasará por el "try", y, en caso de excepción siempre se liberaría la instancia en luego de "finally". Tal vez en este caso concreto esto no fuera un problema, pero, quizá por mala costumbre suelo hacer así las cosas.