Solved

A good Delphi samples site, where?

Posted on 1998-08-25
7
130 Views
Last Modified: 2010-04-04
Hi... where can I find some good delphi examples? for example, When I call a dialog box, then close it.. if I try to call it again, application sends an exception error. I'm freeing the dialog, so.. which may be the problem?

Thanks in advance
Jaime
0
Comment
Question by:skel
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 5

Expert Comment

by:knowlton
ID: 1337693
Can you include a snippet of code showing what you are doing when you make the call?  

I think sometimes you don't need to FREE the dialog, especially when it is being auto-created.
0
 

Author Comment

by:skel
ID: 1337694
There you are the whole method that calles the dialog box:

***************************************************************

Procedure TEmulador.MnuSerialClick(Sender: TObject);
var S1      : string[2];
    S2      : string[7];
    ArchIni : TIniFile;

begin
  with TSetup.Create(Self) do
  ArchIni := TIniFile.Create( 'Monitor.ini' );
  try
    if Setup.ShowModal = 1 then
      begin
        str(Setup.ComPort.ItemIndex+1,S1);
        ArchIni.WriteString( 'Setup', 'Port', S1 );
        str(Setup.m_iBaudRate,S2);
        ArchIni.WriteString( 'Setup', 'BaudRate', S2 );
      end;
  finally
    ArchIni.Free;
    Setup.Free;
  end;
end;

***************************************************************


And these are the methods inside de unit controlling the box:


***************************************************************

procedure TSetup.FormCreate(Sender: TObject);
var S1          : string[2];
    S2          : string[7];
    P,Codigo    : Integer;
    B           : Longint;
    ArchIni     : TIniFile;

begin
  ArchIni := TInifile.Create('Monitor.ini');
  S1 := ArchIni.ReadString('Setup', 'Port', '2');
  val(S1,P,Codigo);
  if Codigo = 0 then
    ComPort.ItemIndex := P-1;
  S2 := ArchIni.ReadString('Setup', 'BaudRate', '19200');
  val(S2,B,Codigo);
  case B of
    110    : BaudRate.ItemIndex := 0;
    300    : BaudRate.ItemIndex := 1;
    600    : BaudRate.ItemIndex := 2;
    1200   : BaudRate.ItemIndex := 3;
    2400   : BaudRate.ItemIndex := 4;
    4800   : BaudRate.ItemIndex := 5;
    9600   : BaudRate.ItemIndex := 6;
    14400  : BaudRate.ItemIndex := 7;
    19200  : BaudRate.ItemIndex := 8;
    38400  : BaudRate.ItemIndex := 9;
    56000  : BaudRate.ItemIndex := 10;
    57600  : BaudRate.ItemIndex := 11;
    115200 : BaudRate.ItemIndex := 12;
  end;
  ArchIni.Free;

end;

procedure TSetup.BaudRateClick(Sender: TObject);
const
    BaudRates: array[ 0..12 ] of Longint =
    ( 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 56000, 57600, 115200 );

begin
  if ( Sender is TRadioGroup ) then
    m_iBaudRate := BaudRates[ ( Sender as TRadioGroup ).ItemIndex ]
  else
    m_iBaudRate := -1;
end;

***************************************************************

Any help would be greatly appreciated...

Thanks in advance
Jaime
0
 
LVL 5

Expert Comment

by:knowlton
ID: 1337695
Do you have a way to send me a demo with the source code included?

My e-mail is:  knowltonfamily@yahoo.com

I've had trouble with this in the past (creating dialogs at run-time and then having them crash when I close / open them again) and I know part of the problem has to do with whether Delphi is auto-creating the form or not.  This can be found under the OPTIONS for the Delphi project.  The OPTIONS button is right next to the Add File and Delete File buttons.

Tom
0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
LVL 8

Expert Comment

by:ZifNab
ID: 1337696
Hi skel!

 Look at delphi deli website.

 There is a search feature which connects you to chami's place for delphi examples.

Regards, Zif.
0
 

Author Comment

by:skel
ID: 1337697
If you write the URL of the delphi deli website, I will be very very happy :)
0
 
LVL 3

Accepted Solution

by:
philipleighs earned 50 total points
ID: 1337698
Hi,

The problem is in the first procedure you listed above. After the "with" on the first line, you need a "begin" so that the rest of the procedure is inside the "with". Currently only the next line is enclosed in the "with". Better still, get rid of that nasty "with" and declare a local variable for the dialog called "SetupDialog" or something. Note that "Setup" is a global instance of the dialog.
Also, make sure that TSetup is not autocreated. Go into Project | Options to check.
Also, you should never Free a dialog, you should only ever Release it. Read the help for the reason why.
The code should look like:


Procedure TEmulador.MnuSerialClick(Sender: TObject);
var S1      : string[2];
    S2      : string[7];
    ArchIni : TIniFile;
    SetupDialog: TSetup;
begin
  SetupDialog := TSetup.Create(Application);
  ArchIni := TIniFile.Create( 'Monitor.ini' );
  try
    if SetupDialog.ShowModal = 1 then
      begin
        str(SetupDialog.ComPort.ItemIndex+1,S1);
        ArchIni.WriteString( 'Setup', 'Port', S1 );
        str(SetupDialog.m_iBaudRate,S2);
        ArchIni.WriteString( 'Setup', 'BaudRate', S2 );
      end;
  finally
    ArchIni.Free;
    SetupDialog.Release;
  end;
end;
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1337699
hi skel, http://delphi.lehner.at/ Zif.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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 …

830 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