Solved

A good Delphi samples site, where?

Posted on 1998-08-25
7
133 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
[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
  • 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
Technology Partners: 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 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month5 days, 19 hours left to enroll

627 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