Jump to content

Running .txt file from same place where is located .exe

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
delphiproblematic

delphiproblematic

    Newbie

  • Members
  • PipPip
  • 11 posts
How to do this ? Sugestion ? Advice ? :crying:

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
What are you trying to do? You can't "run" a text file, just open it, display it, etc.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
abdul.gafur

abdul.gafur

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
Get it with googling, if you find any problem, we will discuss later

#4
Firebird_38

Firebird_38

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
To get the name of the file, no metter where the exe is:
function ExePathFileName(FileName:String):String;
begin
 result:=ExtractFilePath(Application.ExeName)+FileName;
end;

If your EXE is 'C:\Dev\LoadAppText\MyAppTextLoader.exe' then a call to ExePathFileName('MyText.txt') will return 'C:\Dev\LoadAppText\MyText.txt'.

Now that yourt app knows where it's at, you can "run" it:

Add a form.
Add a Memo to the form
Name the Memo "TextMemo"
Add a button. Set caption to "Load text".
Double-click the button.

Type:
 TextMemo.Lines.LoadFromFile(ExePathFileName('MyText.txt'));

This will display your text. If you want to "run" text, this text must be source code. This source code must be accompanied by a compiler or interpreter. You must then instruct the appropriate compiler or interpreter to either compile or interpret it using the appropriate controls and or commands available in such a compiler or interpreter according to the manual that comes with it, or the online documentation, or the newsgroups that provide such information. Please be advised that the langauge used in the txt file must match the language used by the compiler or interpreter. (Much like you need to be able to understand English to understand this post).

To fire up notepad, use ShellExecute. Type "ShellExecute" in your delphi code editor and hit F1. If any terms seem unfamiliar in the manual/help, click on the underlined words (these are hyperlinks). Hope this helps.