Delphi 2010 - I have a routine which takes a string and processes it. There are 3 different types of processing, and I may need any combination, including all 3 ways of processing. I am trying to determine how to call my routine, but everything I try is causing issues. What I want to do is call the procedure something like this...
StringProcess(StartString1, VarProcess1, VarProcess2, VarProcess3);
but it could just as easily be this is I only want 2 of the processes
StringProcess(StartString1, '', VarProcess2, VarProcess3);
The procedure definition is something like
procedure StringProcess(StartString: string; var S1:String; var S2:string; var S3:string);
So in summary... How do I define my procedure to return between 1 and 3 VAR variables? Delphi is wanting me to always pass 3 variables, and I just have to ignore the one if I don't need it. Is there a way to pass "non-existant" VAR parameters, and just ignore them as needed?
Thanks
The issue is that your StringProcess
rountine must have variables to represent S1, S2 and S3 whenever it tries to modify these values. No doubt you don't want to go through the headache of declaring variables for values you're not interested in.
One option to consider is bundling all the variables into a record structure as follows:
type
TStringData = record
S1, S2, S3: string;
end;
procedure StringProcess(StartString: string; var StringData: TStringData);
However I'd go a step further. I suspect you aren't really using inputs of S1, S2 and S3 in your StringProcess
routine. Which means they may as well be out parameters. In which case I'd rather suggest you write:
function StringProcess(StartString: string): TStringData;