Solved

dialogs

Posted on 1998-10-22
3
187 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 100 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

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

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
Note: This is the third blog post in a series on email clearinghouses (https://www.xmatters.com/alert-management/blog-email-has-failed-us?utm_campaign=70138000000ydLoAAI&utm_source=exex&utm_medium=article&utm_content=blog-post).   We’ve been talki…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

932 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

10 Experts available now in Live!

Get 1:1 Help Now