-4

I have the following code:

procedure TForm2.actStareLivratExecute(Sender: TObject);
begin
if dbmodule.comenziDataSetlivrare.AsString = 'pick up' then
actEmailPickup.Execute
else
actEmailLivrare.Execute;
end;

Which works well, if 'pick up' is found in the specified field then it executes actEmailPickup if not it executes actEmailLivrare.

I would like to add 2 more actions to execute, besides these:

actSendSMSLivrare.Execute

actSendSMSPickup.Execute

It should be something like this:

begin
if dbmodule.comenziDataSetlivrare.AsString = 'pick up' then
actEmailPickup.Execute
actSendSMSPickup.Execute
else
actEmailLivrare.Execute
actSendSMSLivrare.Execute;
end;

Unfortunately this doesn't work, returns an error something relating to Boolean, as I'm fairly new I haven't been able to get to the bottom of this.

What should my final code look like, if at all possible to do this?

I'm using Rad Studio 10 Seattle.

Ken White
  • 123,280
  • 14
  • 225
  • 444
t1f
  • 3,021
  • 3
  • 31
  • 61
  • 2
    Pascal needs a semi-colons between statements. Also, if you want both actEmailPickup AND actSendSMSPickUp to execute if your first `if ...then` is true, they need to be surrounded by a begin/end block – MartynA Dec 08 '16 at 18:55
  • 6
    [...reading the documentation helps](http://docwiki.embarcadero.com/RADStudio/en/Declarations_and_Statements_(Delphi)#Structured_Statements) – J... Dec 08 '16 at 19:07
  • 1
    Documentation. Why oh why didn't you read it. – David Heffernan Dec 08 '16 at 19:14
  • 1
    [This tutorial I wrote for InnoSetup](http://stackoverflow.com/a/28221465/62576) might help, as it uses the same basic syntax as Delphi. – Ken White Dec 08 '16 at 19:41
  • @DavidHeffernan - I'm not native English and I have a hard time search for terms / keywords to find stuff, I simply didn't find it, however stupid that may sound :) too bad people are quick to downvote, whoever they may be. Thanks! – t1f Dec 08 '16 at 20:59
  • @J... Thank you, bookmarked and read. – t1f Dec 08 '16 at 20:59
  • @KenWhite Awesome resource, enlightening, bookmarked it also, thank you :) – t1f Dec 08 '16 at 21:00
  • 1
    Your English is good. You didn't read the documentation at all though. – David Heffernan Dec 08 '16 at 21:09
  • @DavidHeffernan - It didn't cross my mind to search for if, or then, or else. That's the part I was referring to when saying about "english is not good" - not knowing these things as I'm just starting out, most of the time I don't have the 'aha' moment to actually come up with the simple keyword to use and search, I know, it sounds stupid and improbable, but it happens. No laziness or so on intended. I'll probably get used to it over time and manage to understand stuff better as to have an insight on what, how and when to search. Either way, I genuinely appreciate the help :) – t1f Dec 08 '16 at 21:13
  • 1
    Cool. The language documentation is pretty good. Worth a good read. Enjoy. – David Heffernan Dec 08 '16 at 21:15
  • 1
    Just for your future reference: The help file contains the entire Delphi language guide. See the main help, Contents tab, RAD Studio Topics->Programming Languages->Delphi Language Reference->Delphi Language Guide. You don't even have to have an internet connection to access it. – Ken White Dec 08 '16 at 21:45
  • @KenWhite Thanks for the tip! Will do. – t1f Dec 08 '16 at 22:22
  • A Google search for `delphi if then else` turned up endless relevant results... – Jerry Dodge Dec 08 '16 at 22:48

1 Answers1

2

Try

if dbmodule.comenziDataSetlivrare.AsString = 'pick up' then begin
  actEmailPickup.Execute;
  actSendSMSPickup.Execute
end
else begin
  actEmailLivrare.Execute;
  actSendSMSLivrare.Execute
end;

As I said, Pascal needs a semicolon between statements and a begin/end pair around them if they are to execute as a block. actSendSMSPickup.Execute and actSendSMSLivrare.Execute don't need semicolons after them because the end after each of them is not a statement, and so the executes don't need separating from it.

MartynA
  • 30,454
  • 4
  • 32
  • 73
  • Hey Martyn, thanks for another great answer. One small issue, everything is sending except for the `actSendSMSLivrare.Execute` when pick up is not found. actEmailLivrare does execute, but not the sms action. Any ideas? – t1f Dec 08 '16 at 19:10
  • Nevermind, I just noticed a small typo I had in the actSendSMSLivrare action, sorry about that Martyn, everything works great now, thank you! – t1f Dec 08 '16 at 19:13
  • Well, if you've edited it exactly as I've written it, `actSendSMSLivrare.Execute` will execute if `actEmailLivrare.Execute` does. So if it seems not to execute, put a breakpoint on `actSendSMSLivrare.Execute`. When the debugger reaches there, press F7 to tract into your action; perhaps that will show why it does not appear to be executing. – MartynA Dec 08 '16 at 19:16
  • No no, It was a problem in the actual code of the action named actSendSMSLivrare, causing it not to do anything, my mistake - your code works fine :D thank you – t1f Dec 08 '16 at 20:57