Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

A good Delphi samples site, where?

Posted on 1998-08-25
7
Medium Priority
?
136 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:Tom 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:Tom 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 200 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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…
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 teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

972 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