Solved

dialogs

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
TZConnection connected in separate thread 2 1,003
Android Application not running 1 491
Intraweb submit form as a POST request 4 304
Pass a string reference from one unit to another 8 116
In this article we will learn how to backup a VMware farm using Nakivo Backup & Replication. In this tutorial we will install the software on a Windows 2012 R2 Server.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

821 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