I would like to creat a file with a variable file name as follows:
{1st version}
procedure TForm1.Button1Click(Sender: TObject);
var
number2: integer;
begin
number2:=1;
FileCreate('soundwave', number2, '.wav');
end;
The compiler returns "too many actual parameters"
So I tried this
{2nd version}
procedure TForm1.Button1Click(Sender: TObject);
var
number1: integer;
begin
number1:=1;
Name:= 'soundwave'+ IntToStr(number1)+'.wav';
FileCreate(Name);
end;
The program returns "soundwave1 is not a valid component name"
Any suggestions would be greatly appreciated.
Comments
:
:
: {1st version}
: procedure TForm1.Button1Click(Sender: TObject);
: var
: number2: integer;
: begin
: number2:=1;
: FileCreate('soundwave', number2, '.wav');
: end;
:
:
: The compiler returns "too many actual parameters"
: So I tried this
:
:
: {2nd version}
: procedure TForm1.Button1Click(Sender: TObject);
: var
: number1: integer;
: begin
: number1:=1;
: Name:= 'soundwave'+ IntToStr(number1)+'.wav';
: FileCreate(Name);
: end;
:
: The program returns "soundwave1 is not a valid component name"
:
:
: Any suggestions would be greatly appreciated.
:
:
:
First of all: Name is a property of all components, including all forms.
If you remove the step of assigning a value to name and then use that value in FileCreate() you have a working code:
[code]
MyFileHandle := FileCreate('soundwave'+ IntToStr(number1)+'.wav');
[/code]
But why don't you use the native pascal routines: AssignFile(), Rewrite(), and CloseFile(). These automatically create a file if it doesn't exist. Also these are easier to access.
: procedure TForm1.Button1Click(Sender: TObject);
: var
: number1: integer;
: begin
: number1:=1;
: Name:= 'soundwave'+ IntToStr(number1)+'.wav';
: FileCreate(Name);
: end;
:
first of all: you get the error message becuase you are trying to set the Name property of the Button1 - you did not declare a local Name variable so the program attempts the use the wrong Name var - hence the error!
anyway, try this code instead:
[code]
FileCreate('soundwave'+ IntToStr(number1)+'.wav');
[/code]
NB: in general temporary var's should be avoided if you dont really need them. they might look handy during development but you pay a price in performance and elegance.