1

I know this is a ridiculous question and I admit I am not really good with Delphi yet. I am passing a function but could not get through with the declaration. I just need a real quick help.

My Declaration:

type
  TfrmApp = class(TForm)
    function GetDosOutput : string;     // error is pointing here

My Function:

function GetDosOutput(CommandLine: string; Work: string = 'C:\'): string;

There must be something missing with my declaration. I've tried putting parameters, did all the messy work-arounds, searching for answers everywhere. I even look for declaration tutorials but no avail. If you have any good reference for this I would love to get one and deep dive right away.

Just a quick one, please help.


Help Needed: I was trying to run this but when I tried to compile the compiler message pops "There are errors". And when I click "Ok", it highlights in red the following declaration line:

function GetDosOutput : string;
Disillusioned
  • 14,635
  • 3
  • 43
  • 77
Ciodensky
  • 59
  • 1
  • 1
  • 11
  • 1
    I don't believe you really want help. You haven't even bothered to post your error message. And your code is not complete. – Disillusioned Jan 14 '18 at 00:57
  • You shouldn't be defining any methods in this section of the class. You should put it under `private` or `public` instead. Where you have it now (based on the code you've shown) is only meant for things auto-inserted by the IDE's form designer. That wouldn't cause your problem, but you haven't explained enough of your problem details either. – Jerry Dodge Jan 14 '18 at 01:04
  • @Craig Young Sorry. Actually this is always I get hit here. I've been always asked about error message but some of the errors I get don't give any error message. I swear, when I compile this, a message box says "There are errors" only. And when I press "Ok", the function line declaration get highlighted in red. – Ciodensky Jan 14 '18 at 01:07
  • 1
    You should look in your `messages` output section at the bottom of the IDE (by default) for the error messages. – Jerry Dodge Jan 14 '18 at 01:07
  • 2
    @Cioden The dialog is a summary, it tells you the number of errors, hints and warnings you received. The detail of the errors is in a messages window. By default this will be docked at the bottom of Delphi with the first error selected. Each error is associated with the line of code that triggered the error. In your case I would guess the error is telling you that you haven't implemented the function. _A guess only, because you have not provided enough information._ – Disillusioned Jan 14 '18 at 01:12
  • PS: Once you've found the error message, you should search here first. Because quite possibly your question has been asked and answered already. – Disillusioned Jan 14 '18 at 01:14
  • OMG! At least someone kind enough to guide me at last! Thanks to you guys!. I am looking at it right now. Get back to you shortly, this time more sensible one. – Ciodensky Jan 14 '18 at 01:20
  • 1
    Your two function names are different. `GetOutputDos` vs. `GetDosOutput`. If your function in your second code snippet is supposed to correspond as the implementation of the first one, then first of all they need to match names and signatures, and second of all you'd need the class name in front of the function name. For example, `TfrmApp.GetDosOutput`... Better yet, define it in one place or the other, and use code completion to automatically insert the corresponding part. – Jerry Dodge Jan 14 '18 at 01:20
  • @Craig Young Thanks for the Output Message guidance. – Ciodensky Jan 14 '18 at 01:35
  • @Jerry Dodge as well. Thanks so much. – Ciodensky Jan 14 '18 at 01:36
  • @Cioden I've rolled back most of your edits since version 2. There's no need to edit the solution into your answer as this is clearly indicated by the ***accepted answer***. Also you had deleted the line declaring the class leaving you with `type private function` which would give you an entirely different error! More importantly, you still have not shown the actual error message you were getting; which based on your accepted answer should be something along the lines of a `E Unsatisfied declaration...` – Disillusioned Jan 14 '18 at 03:44
  • @Cioden It looks like you made the same mistake as before in ***your own question*** from last year: https://stackoverflow.com/q/43302716/224704 _Did you not learn from Martyn's very detailed answer?_ – Disillusioned Jan 14 '18 at 03:56
  • Yes @CraigYoung. Thanks for noting me on that. I didn't bother to look into it because I was consumed by it then. It just sometimes while my eagerness to resolve some of my issues and excitement perhaps, I tend to miss some details. I am still learning and this one is a big blow to me. After Alex_89 shared the solution, I was so embarrassed. I realized that I know this error very well. Rest assured that I'll be more careful next time. – Ciodensky Jan 14 '18 at 06:58
  • @Cioden: I suggest you read a book or tutorial on the language and on using the IDE (most of that info comes with Delphi as help files) before you start coding. It is clear you are not familiar with the language nor with the IDE. – Rudy Velthuis Jan 14 '18 at 22:28

1 Answers1

3

Ok, you're supposed to declare the function in the private/public section of the class (in this case, your class is the TfrmApp form), and implement it in the "implementation" section:

type
  TfrmApp = class(TForm)
  public
      function GetDosOutput(CommandLine: string; Work: string = 'C:\'): string;
  end;

implementation

  function TfrmApp.GetDosOutput(CommandLine: string; Work: string): string;
  begin
      // your code here...
  end;

After you've declared the function public, just press ctrl+shift+c from within the TfrmApp class and a new skeleton for the implementation will appear.

This is very basic, as you already know. You should really read some introductory tutorials on OOP, 'cause you're probably going to need a separate class for pretty much anything, then work with it in your form.

Alex_89
  • 371
  • 5
  • 15
  • How are you so sure this is OP's problem when they haven't given us enough information to identify any issue? It could be that the function is implemented, but has a different signature than defined. We have no idea from our position. – Jerry Dodge Jan 14 '18 at 01:19
  • 1
    It's pretty clear that the error is a non-implemented declaration. @Cioden's question is not well written, but with the little info he provided (his 3 lines of code) there's an obvious difference in definition-implementation. I'm saying it's just good practice to create an exclusive class to work with, he might not even know that. – Alex_89 Jan 14 '18 at 01:27
  • @Jerry Dodge Apologies for the different signature but that does not add actually to the error. I think I wrote it wrongly here. – Ciodensky Jan 14 '18 at 01:30
  • @Cioden I'm confused then, did this answer help you fix your problem or not? Your comment suggests that it's still unsolved, yet you've accepted this answer. – Jerry Dodge Jan 14 '18 at 01:33
  • @Alex_89 Thanks for taking time to draft a code for me. It saves a lot of potential hours to crack again. All the comments/inputs actually did really help plus guidance bonus! I am a newbie and I promised, I'll be better next time. – Ciodensky Jan 14 '18 at 01:34
  • Look @Cioden, it doesn't matter if you think your question is ridiculous or not, EVERY single one of us had to start somewhere, and ALL of us remember what it was like to not have a clue at first. I really encourage you to read every comment here, they're all constructive, and have a point. Find some good Delphi tutorials, and you're good to go. We're all here to help. After all we've all been there, trust me. – Alex_89 Jan 14 '18 at 01:42
  • @Alex_89 Thanks so much. Greatly appreciate those words! It pushes me to do more and fast. No worries I am old enough to handle constructive criticisms. Though, so far, its been a lot already! yet I am prepared. Thanks again and God Bless! – Ciodensky Jan 14 '18 at 01:53
  • Yes @Jerry Dodge it is. I supposed the error was answered when I moved the declaration to public and replicate exactly the function implementation declaration. – Ciodensky Jan 14 '18 at 02:17