Hi,
several years ago I used "code macros" in 8051-assembler language. I wonder (and hope) if something similar is possible in Lazarus / FreePascal?
Since I haven't seen anythin like it since then, I'll try to make clear what I'm talking about in an example:
Let's say I have a group of function to read some value:
ReadInt
ReadBool
ReadStr
ReadObject ...
All these functions use exactly the same code - maybe something like this:
function ReadInteger(InVal: Integer): Integer
var
TmpVal: Integer
begin
TmpVal := GetIt(InVal);
Result := DoSomeMore(TmpVal);
end;
The only difference between the functions is the variable type for TmpVal and the functions result type.
What I'm dreaming of is a macro language that enables me to do the following:
{$define macro MyMacro(Param1, ParamN)}
function Read{Param1}(InVal: {ParamN}): {ParamN}
var
TmpVal: {ParamN}
begin
TmpVal := GetIt(InVal);
Result := DoSomeMore(TmpVal);
end;
{$endmacro}
{$UseMacro MyMacro(Int, Integer)}
{$UseMacro MyMacro(Str, String)}
{$UseMacro MyMacro(Bool, Boolean)}
{$UseMacro MyMacro(Object, TObject)}
I hope this is understandable.
Is anything like that possible in or planned for FreePascal or Lazarus?