Apparently you misunderstood my response. The lines of code in a file cannot be executed without being compiled.
There are command line compilers to compile code, which are actually projects, but that would not allow for code blocks to be used from within your application.
alex1 said:
... Its seeing it just like a string line,so after the file is loaded its writing on the screen:
gotoxy(10,25);write('hello');
That's because it IS a string! gotoxy and write are commands that direct a COMPILER what to do NOT the operating system. These commands are not like .bat file commands back in the day.
alex1 said:
How can I make it to be recognised as a command and to do whatever the code is saying?
This is why I asked exactly what you are doing. You cannot use the string from a file as commands. However, you can "simulate" a compiler from your application. Basically look to see if a command is in the string from the file. If there is a command, get the information from it and execute the command.
An example of the two lines you wanted to execute...
var
f: text;
s, SubStr1: string;
i,x,y: Integer;
begin
Assign(f,'level1.lvl');
Reset(f);
while not eof(f) do
begin
Readln(f,s);
{Check if this line is a gotoxy command. If it is then execute the command}
if Pos('gotoxy',S) <> 0 then
begin
i := Pos('(', S);
SubStr1 := Copy(S, i+1 , (Length(S) - i-2)); // Returns X,Y
X := StrToInt(Copy(SubStr1,1,2));
Y := StrToInt(Copy(SubStr1,4,2));
gotoxy(X,Y);
end else
{Check this line to see if it is a write command. If it is execute the command}
if Pos('write',S) <> 0 then
begin
i := Pos('(', S);
SubStr1 := Copy(S, i+2 , (Length(S) - i) -4);
write(SubStr1);
end else
write(s);
end;
close(f);
end.