Page 1 of 1

Using DataCAD standard menus in Dcal for Delphi?

PostPosted: Mon Mar 20, 2006 6:54 am
by rod_walker
Hi,
I have been experimenting with Dcal for Delphi by simply drawing a batten. That is a rectangle with a cross. The user specifies width and depth and outline color and cross color, the batten is then drawn at the users click point. All works fine. The portion of code that sets the menu is as follows:

Code: Select allif act <> alsize then
         begin
          wrterr ('batten version 1.0');
            case b.state of
            1:
              begin
                wrtlvl('batten');
                lblsinit;
                lblset (2,'Width');
                lblset (3,'Depth');
                lblset (5,'RectClr');
                lblset (6,'xClr');
                lblset (7,'Erase');
                lblset (20,'Exit');
                lblson;
                wrtmsg('Enter ip Point or select option');
                getpoint(b.getp,retval);
               end;
             2:
               begin
                 wrtmsg('enter Width');
                 getdis(b.Width,b.getd,retval);
                 b.state:=1;
               end;
              3:
               begin
                  wrtmsg('enter depth');
                  getdis(b.depth,b.getd,retval);
                  b.state:=1;
               end;
              5:
               begin
                 wrtmsg ('select outline color');
                 getclr(b.outlineClr,b.getc,retval);
                 b.state:=1;
                end;
              6:
               begin
                 wrtmsg ('select cross color');
                 getclr(b.xClr,b.getc,retval);
                 b.state:=1;
                end;
               7:
                begin

                  MenuErase(retval);
                { b.state:=1;}
                end;
               else
               retval := XDone;
             end;

             end;
             result:=retval;
 end;

When clicking on F7 the Erase menu is displayed, and works except on exiting the Erase menu I am kicked out of the macro.
UInterfaces.pas lists :
Procedure menuErase(Var iwant:wantTpe);stdcall;external Appname;
I can't find any definition of wantType in the Header files. Is there something I am missing?



Rod Walker

PostPosted: Mon Mar 20, 2006 9:20 am
by devinder
Hi,
What happens when you change the commented line in State 7 from
{b.state := 1;}
to
b.state := 1;

OR you will need to add the return state for 7 and then set b.state := 1;

i.e.
Code: Select allFunction TestMain(act: action; pl, pargs: Pointer): wantType;
var
   retval: asint;
   b: PBattenL;
BEGIN
   b := PBattenL(pl);
   if act = aagain then
   begin
      case b.state of
                 1 : Begin
                       // You probable have code here
                      End;
              //After you exit from erase menu b.state is still set to 7 and should be handled here,
             // otherwise else part of case will set b.state = 0 and exit out of macro.
                 7: Begin
                            b.state := 1;
                     End;
                 else begin
                             b.state := 0;
                   end;
             end;//case
     end;




wantType is defined in 'URecords.pas' and declared as integer. The value of Retval in EraseMenu is returned by DataCAD and will be the internal menu number for erase menu and later call the erase menu.

PostPosted: Wed Mar 22, 2006 8:46 am
by rod_walker
Thanks Devinder,
With my original code flagging b.state=1 in the if act<> alsize section then I was stuck in the erase menu, hence commenting out. With your correct solution flagging the b.state in if act =aagain section solved my problem. I also thought I had a logic problem since after selecting outline color the macro would draw the batten. Removing the b.state:=1 and relocating it as shown below solved my problem.

Code: Select allFunction battenMain(act:action;pl, pargs: Pointer): wantType;
 var
   retval: asint;
   b: Pbatten;
 
 begin
   b:=Pbatten(pl);
   if act = aagain then
    begin
     case b.state of
      1:
        begin
           if b.getp.Result = res_escape then {function key picked}
             begin
              case b.getp.key of
               f2: b.state:=2;
               f3: b.state:=3;
               f5: b.state:=5;
               f6: b.state:=6;
               f7: b.state:=7;
               s0: b.state:=0;
              end;// caseb.getp.key
            end
            else if b.getp.Result = res_normal then {ip point selected}
             begin
             b.ip:=b.getp.curs ;
             drawbatten(b.ip,b.outlineClr,b.xClr,b.Width,b.depth);
            end;//if getp.result
           end;
         2..7:Begin     {catch all b.states here Devinders solution}
           b.state:=1;
           end;
         else b.state:=0;
        end;//case b.state
      end;