Solved

dialogs

Posted on 1998-10-22
3
191 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convertion SDK Vc++ to Delphi - fingerprint reader 5 831
Delphi Timer?   How do I schedule an event every hour on the hour? 2 903
Delphi Ascii code 2 1,046
HTTP-POST Delphi 7 5 3,099
Invest in your employees with these five simple steps to improve employee engagement and retention.
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
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 …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 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