Solved

Problem with the ABORT procedure

Posted on 1998-12-09
2
335 Views
Last Modified: 2011-09-20
I was developing apps in Delphi 1.0. I migrated the project
to Delphi 3.0. But I got the compiling error with the following code:

procedure TfCliente.TableBeforeCancel(DataSet: TDataset);

BEGIN
   If MessageDlg('Cancel?', mtConfirmation,
                 [mbYes, mbNo], 0) = mrNo Then
        Abort;
END;

Delphi says "Statement expected, but expression of type 'integer' found."

It's strange because I always used the ABORT procedure to cancel the TTable's Before procedures, but now in Delphi 3.0 it won't compile. I tried to put the ABORT procedure in other codes, it just shows the same error.

In this case will this be Delphi 3.0's bug?
 
0
Comment
Question by:davihongsikchoi
2 Comments
 
LVL 2

Accepted Solution

by:
gallaghe earned 200 total points
ID: 1350091
I think the problem has something to do with either the order of the units USES clause or a unit is missing from the unit.

try using my "Message" unit, (this isolates the call to MessageDlg) add it to the form;s uses clause which is causing the problem. Then use the function called "Question".

Caveat: Each of my routines allow you to do multi-lines in the messages by using a semi-colon rather then #13.

For example:
'This is line 1' + #13 + 'Line 2' ;

My method
'This is line 1;Line 2' ;


Demo call
procedure TfrmMain.Table1BeforeCancel(DataSet: TDataSet);
begin
  if not Question('Cancel?') then
    abort ;
end;

-------------Source code -------------------------
unit kg_MsgDlg ;

interface

uses
  Windows, Messages, Classes, Graphics;

function  Confirmation(const S: String): Word ;
function  Question(const S: String):Boolean ;
procedure Information(const S: String) ;
procedure InformationPos(const S: String;nRow,nCol:Integer) ;
procedure Alert(const S: String) ;
procedure ErrMsg(const S: String) ;
function  RetryBox(const S: String):Boolean ;
function  StrCrLf(const cMsg:String):String ;

implementation

uses SysUtils, Controls, Forms, Consts, Dialogs ;

function StrCrLf(const cMsg:String):String ;
var nLen,i:Integer ;
begin

  nLen := Length(cMsg) ;
  i := 1 ;
  while i <= nLen do begin
    if cMsg[i] in [';','~'] then
      Result := Result + #13
    else
      Result := Result + cMsg[i] ;
    Inc(i) ;
  end ;
end ;

function Confirmation(const S: String): Word ;
begin
  case MessageDlg(StrCrLf(S),mtConfirmation,[mbYes,mbNo,mbCancel],0) of
     IDYES    : Result := mrYes ;
     IDNO     : Result := mrNo ;
     IDCANCEL : Result := mrCancel ;
     else       Result := mrCancel ;
  end
end ;

procedure Alert(const S: String) ;
begin
  MessageDlg(StrCrLf(S),mtWarning,[mbOk],0) ;
end ;

procedure Information(const S: String) ;
begin
  MessageDlg(StrCrLf(S),mtInformation,[mbOk],0) ;
end ;

procedure InformationPos(const S: String;nRow,nCol:Integer) ;
begin
  MessageDlgPos(StrCrLf(S),mtInformation,[mbOk],0,nCol,nRow) ;
end ;

procedure ErrMsg(const S: String) ;
begin
  MessageDlg(StrCrLf(S),mtError,[mbOk],0) ;
end ;

function Question(const S: String):Boolean ;
begin
  case MessageDlg(StrCrLf(S),mtConfirmation,[mbYes,mbNo],0) of
     IDYES    : Result := True ;
     IDNO     : Result := False ;
  else          Result := False ;
  end ;
end ;

function RetryBox(const S: String):Boolean ;
begin
  case MessageDlg(StrCrLf(S),mtConfirmation,[mbRetry,mbNo],0) of
     IDRETRY  : Result := True ;
     IDNO     : Result := False ;
  else          Result := False ;
  end ;
end ;

end.


Kevin S. Gallagher
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1350092
hi davihongsikchoi,

are you sure that your codefragment causes your problem? I've checked out and compiled it with D3 without errors.

Or if there a other defined by own Abort procedure? if so use sysutils.abort instead.

meikl
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now