Solved

A good Delphi samples site, where?

Posted on 1998-08-25
7
127 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
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.

 
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

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 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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

867 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

21 Experts available now in Live!

Get 1:1 Help Now