i have this code here:
type // This Enumerator Type for Handling the Registry Results ...
TRegistryKind = (rkBOOL, rkSTRING, rkEXPANDSTR, rkINTEGER, rkFLOAT, rkCURRENCY, rkBINARY_DATA, rkDATE, rkTIME, rkDATE_TIME);
TRegistryKindResult = record
AsBool: Boolean;
AsString: string;
AsInteger: Integer;
AsFloat: Single;
AsCurrency: Currency;
end;
what i need here is to create a single procedure with universal pram that accept any kind of input Types and save them to registry ..
here is the trick:
procedure TAppSettings.Save_Setting_ToRegistry(AKey, AItem_Setting: String;
AValue: **UnknownType**; ARegKind: TRegistryKind);
var
Reg: TRegIniFile;
begin
Reg := TRegIniFile.Create(AKey);
try
case ARegKind of
rkBOOL: Reg.WriteBool('', AItem_Setting, AValue);
rkSTRING: Reg.WriteString('', AItem_Setting, AValue);
end;
Reg.CloseKey;
finally
Reg.Free;
end;
end;
what should i do for the param AValue ? is there a smart way that can tell my Delphi IDE to accept any input from the 5 kinds that i defined in TRegistryKindResult record above?
The old-school approach is to use variants. Then, in fact, you don't even need the
TRegistryKind
parameter:To test it: