Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

dialogs

Posted on 1998-10-22
3
Medium Priority
?
200 Views
Last Modified: 2010-04-16
I have written this program in Borland TPW 1.5, and i keep getting application errors. please help, the file is stock.res is available by emailing me(i don't think you can upload files).

program Stock_exchange;

{$R STOCK.res}

uses WinTypes, WinProcs, WObjects, wincrt;

type
  PTestDialog = ^TTestDialog;
  TTestDialog = object(TDialog)
    procedure butt(var Msg: TMessage); virtual id_First + 159 ;  
   end;

type
  PMyWindow=^TMyWindow;
  TMyWindow=object(TWindow)
    constructor Init(AParent: PWindowsObject; Atitle: PChar);
    procedure players(var msg:tmessage); virtual cm_first + 51;
  end;    
     
  TMyApplication = object(TApplication)
    procedure InitMainWindow;virtual;    
  end;
   
var MyApp:TMyApplication;          
 
constructor TMyWindow.Init(AParent: PWindowsObject; Atitle: PChar);
begin  
  TWindow.Init(AParent, Atitle);
  attr.menu :=loadmenu(hinstance, pchar(100));
end;

procedure ttestdialog.butt(var msg: tmessage);
var TextItem: PChar;
begin
 getdlgitemtext(getdlgitem(hwindow,151),151,textitem,20);
 
end;

procedure TMyWindow.Players(var Msg: tmessage);
begin
     Application^.ExecDialog(New(PTestDialog, Init(@Self, 'DIALOG_1')));
end;

procedure TMyApplication.InitMainWindow;
begin
  MainWindow:=New(PMyWindow, Init(nil,'Menus'));
end;

begin
   myapp.init('Video');
   myapp.run;
   myapp.done;
end.
 
please help!

Please use POBWEST@YAHOO.COM (as i can't read mail from the stated one in the profile for the next week)
0
Comment
Question by:pobwest
  • 2
3 Comments
 
LVL 2

Expert Comment

by:joe_h
ID: 1215841
Mail me the complete code, I'll have a look :)

joe@hw.cz

0
 
LVL 2

Accepted Solution

by:
joe_h earned 400 total points
ID: 1215842
Problem is

   procedure ttestdialog.butt(var msg: tmessage);
    var TextItem: PChar;  {<-------- HERE.}
    begin
     getdlgitemtext(getdlgitem(hwindow,151),151,textitem,20);
    end;    

The thing is, that by saying 'var textitem:PChar' you declare a pointer, which, at this moment, POINTS SOMEWHERE, BUT NOBODY KNOWS WHERE. So, a call to getdlgitemtext will result in up to 20 bytes (the last parameter) being changed somewhere in memory, causing Windows to crash - you have never actually allocated space for the resulting string.

I guess you meant to write something like:
   procedure ttestdialog.butt(var msg: tmessage);
    var TextItem: array[0..20] of char;
    begin
     getdlgitemtext(getdlgitem(hwindow,151),151,@textitem,20);
    end;

Here, ther 'var' statement actually allocates 21 bytes (I like to put an extra byte in for safety) for the string, while the @textitem returns a pointer to this allocated space.

HTH, Joe
 
0
 

Author Comment

by:pobwest
ID: 1215843
That the one!

I changed the procedure to this

procedure ttestdialog.butt(var msg: tmessage);
var TextItem:array[0..20] of char;
a:integer;
begin
   getdlgitemtext(hwindow,201,textitem,20);
   writeln('Returned Value :',a);
   writeln('Text recived   :',textitem);
end;

and it seems to have done the trick


0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
Take a look at these 6 Outlook Email management tools which can augment the working and performance of Microsoft Outlook to give you a more rewarding emailing experience.
Loops Section Overview
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

916 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