Jump to content

Check out our Community Blogs


Member Since 01 Aug 2008
Offline Last Active Apr 15 2013 03:35 PM

#555569 New to C ++

Posted by Firebird_38 on 13 May 2010 - 12:49 AM

Just to be clear: You don't need any source to create programs...

Except of course, your own source, the source for your program...
  • -1

#552625 How do you Call a function/procedure from another unit. SIMPLE?

Posted by Firebird_38 on 20 April 2010 - 05:06 PM

First off, decide which function in unit1 you want to "share". For instance... Then add those to the "interface" section, but only the header (first line with name and params).

Then, in the "using" unit, add a uses clause (if it's not already there).
uses unit2;
Now you can use the functions defined in the interface of unit1 as if they were defined in unit2. The same goes for types, constants and global variables. Hit ctrl-enter on someone else's unit name in your uses clause to view it's source and see how others do it.

unit unit1;
interface //this is the part you "share" with other4 units, or the "public" part
//You can have a uses clause here, if you're using types or constants from other units in your interface section.
//If you only use things in the implementation, don't add the uit to your interface. This is bad coding...
//That has to do with circular references...
//Units cannot refer to [I]each other[/I] in the interface sections, but one can refere to the other in the interface, and the other can refer back, but only in its implementation...
//Try it and see you get a "circular unit reference" error.
function test(param:TMyType):string;
implementation //this is where the stuff is that is hidden from anyone that "uses" this unit
uses SysUtils; //stuff units you use here is only available from here on down...
function test(param:TMyType):string;
 result:=IntToStr(param.Num1+param.Num2); //this is just a silly test...

And unit2:

unit unit2;
procedure Go;
uses Dialogs,[B]unit1[/B]; //here I'm "stating" that I wanna use the stuff in unit1's interface section...
procedure Go;
var param:TMyType;
 //To call this proc, you must use this unit in a unit that actually does something... :)
 ShowMessage(test(param)); //"ShowMessage" is defined and implemented in the "Dialogs" unit, used above...

This is written off the top of my head, so if it doesn't work don't kill me. I didn't compile to see if I misspelled anything... or forgot something... :)

Happy programming.
  • 1

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

Posted by Firebird_38 on 18 March 2010 - 08:41 AM

To get the name of the file, no metter where the exe is:
function ExePathFileName(FileName:String):String;

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.


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.
  • -1

#543768 mul in 16 bit

Posted by Firebird_38 on 18 February 2010 - 08:41 AM

well, not quite sure what's up here. But it seems your #100 may be 100b, as in binary, which equals 4. Then when you mul 10000h by this, you get 40000h. If you now have a 16bit limit, this may be split into 4h in one register and 0000h in another.
This seems to be the case. :)
  • -1

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download