Solved

dialogs

Posted on 1998-10-22
3
186 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
Comment Utility
Mail me the complete code, I'll have a look :)

joe@hw.cz

0
 
LVL 2

Accepted Solution

by:
joe_h earned 100 total points
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

772 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

14 Experts available now in Live!

Get 1:1 Help Now