Recent

Author Topic: [SOLVED] My form is blank when it opens now?  (Read 9985 times)

georgelappies

  • New Member
  • *
  • Posts: 35
[SOLVED] My form is blank when it opens now?
« on: July 20, 2011, 08:39:41 am »
Hi all

I really hope somebody can assist me with this. I am working on a project and all of a sudden one of my main forms is blank when it opens up now. It definitely worked correctly yesterday. I did not even work on the form today.

I even added code like this
Code: [Select]
objects.Visible:=True
for all the objects on the form under form open.

My only guess is that something went wrong with my project settings.

Any help will be much, much appreciated. 

thanks in advance,

George
« Last Edit: July 20, 2011, 03:21:11 pm by georgelappies »

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: My form is blank when it opens now?
« Reply #1 on: July 20, 2011, 10:13:41 am »
It is probably something wrong with the resource loading. Which resource type do you use? old include LRS or the new $R directive? What about attaching the entire unit and LFM here?

georgelappies

  • New Member
  • *
  • Posts: 35
Re: My form is blank when it opens now?
« Reply #2 on: July 20, 2011, 10:34:48 am »
It is probably something wrong with the resource loading. Which resource type do you use? old include LRS or the new $R directive? What about attaching the entire unit and LFM here?

It is using the
Code: [Select]
{$R *.lfm} directive. Here is the source and form code. It does indeed look like a resource issue because when the form now loads it even has the 'X' logo in the top left for X11 apps instead of the default blue lazarus cheetah paw (which is very cool especially for a thundercats fan  :D)

the pascal source
Code: [Select]
unit startup;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  StdCtrls, ComCtrls, sasol_utils, mysql50conn, sqldb, walkthru;

type

  { TfrmLogin }

  TfrmLogin = class(TForm)
    btnSubmit: TButton;
    edtUser: TLabeledEdit;
    edtPwd: TLabeledEdit;
    MySQLConnection1: TMySQL50Connection;
    SQLQuery1: TSQLQuery;
    SQLTransaction1: TSQLTransaction;
    StatusBar1: TStatusBar;
    procedure btnSubmitClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure exitApp();
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  frmLogin: TfrmLogin;

implementation

{$R *.lfm}

{ TfrmLogin }

procedure TfrmLogin.exitApp();
begin
  Close;
end;

procedure TfrmLogin.FormCreate(Sender: TObject);
{
 Need code here to compare the version of the app with the latest one
 on the database, if client is not the same error box will come up and
 display location to download latest version and then exit application.
}
var
  sqlVersion: String;

begin
  edtUser.Visible:= True;
  edtPwd.Visible:= True;
  btnSubmit.Visible:= True;
  Statusbar1.Visible:= True;

  // Check if we have an active connection. If so, let's close it.
  if MySQLConnection1.Connected then
     begin
          // The SQLTransaction1 gets activated automatically, but before we can close
          // the connection we have to set the SQLTransaction1.Active to false.
          SQLTransaction1.Active := False;
          MySQLConnection1.Close;
     end;

  // Create the sql statement
  sqlVersion := 'select idversion from sasol_kpa.version where version=''' +
                APP_VERSION + '''';

  // Set the connection parameters.
  MySQLConnection1.HostName := DB_HOSTNAME;
  MySQLConnection1.UserName := DB_USER;
  MySQLConnection1.Password := DB_PASSWD;
  MySQLConnection1.DatabaseName := DB_NAME;
  // Open the connection.
  MySQLConnection1.Open;

  // Execute the query
  if MySQLConnection1.Connected then
     begin
          SQLQuery1.SQL.Text := sqlVersion;
          SQLQuery1.Open;
          if (SQLQuery1.IsEmpty) then
             begin
                  MessageDlg('Error! You need to update your app from \\secdapp30\',mtError, mbOKCancel, 0);
                  application.terminate;
             end;
          //ShowMessage('Version Correct!');
     end;
end;

procedure TfrmLogin.btnSubmitClick(Sender: TObject);
{
 This function has to validate the user as well as get some global variables
 set from within the database. If the username or password is incorrect the
 application will exit back to the desktop.
}
var
   sqlLogin: String;


begin
  // Check if we have an active connection. If so, let's close it.
  if MySQLConnection1.Connected then
     begin
          // The SQLTransaction1 gets activated automatically, but before we can close
          // the connection we have to set the SQLTransaction1.Active to false.
          SQLTransaction1.Active := False;
          MySQLConnection1.Close;
     end;

  // Create the sql statement
  sqlLogin := 'SELECT * FROM sasol_kpa.users WHERE UserID='''  +
              edtUser.Text + ''' AND Password=''' + edtPwd.Text + '''';

  // Set the connection parameters.
  MySQLConnection1.HostName := DB_HOSTNAME;
  MySQLConnection1.UserName := DB_USER;
  MySQLConnection1.Password := DB_PASSWD;
  MySQLConnection1.DatabaseName := DB_NAME;
  // Open the connection.
  MySQLConnection1.Open;

  // Execute the query
  if MySQLConnection1.Connected then
     begin
          SQLQuery1.SQL.Text := sqlLogin;
          SQLQuery1.Open;
          if (SQLQuery1.IsEmpty) then
             begin
                  MessageDlg('Error! Please check username and or password!',mtError, mbOKCancel, 0);
                  exit;
             end;

          // get userid from edit box
          USERID_SASOL := edtUser.Text;
          // analyse query to get the real name and default form
          USER_REAL_NAME := SQLQuery1.FieldByName('RealName').AsString;
          USER_DEFAULT_FORM := SQLQuery1.FieldByName('defaultForm').AsString;

          // show the correct form based on username
          if USER_DEFAULT_FORM = 'walkthru' then
             frmWalkthru.Show
          else
              MessageDlg('Error! No default form spesified for user!',mtError, mbOKCancel, 0);

          // hide the login form
          frmLogin.Hide;
     end;
  end;
end.

and the form
Code: [Select]
object frmLogin: TfrmLogin
  Left = 731
  Height = 165
  Top = 234
  Width = 221
  BorderStyle = bsDialog
  Caption = 'Login'
  ClientHeight = 165
  ClientWidth = 221
  OnCreate = FormCreate
  Position = poDesktopCenter
  LCLVersion = '0.9.30'
  Visible = True
  object edtUser: TLabeledEdit
    Left = 16
    Height = 23
    Top = 32
    Width = 80
    EditLabel.AnchorSideLeft.Control = edtUser
    EditLabel.AnchorSideBottom.Control = edtUser
    EditLabel.Left = 16
    EditLabel.Height = 16
    EditLabel.Top = 13
    EditLabel.Width = 62
    EditLabel.Caption = 'Username'
    EditLabel.ParentColor = False
    TabOrder = 0
  end
  object edtPwd: TLabeledEdit
    Left = 16
    Height = 23
    Top = 88
    Width = 80
    EchoMode = emPassword
    EditLabel.AnchorSideLeft.Control = edtPwd
    EditLabel.AnchorSideBottom.Control = edtPwd
    EditLabel.Left = 16
    EditLabel.Height = 16
    EditLabel.Top = 69
    EditLabel.Width = 56
    EditLabel.Caption = 'Password'
    EditLabel.ParentColor = False
    PasswordChar = '*'
    TabOrder = 1
  end
  object btnSubmit: TButton
    Left = 128
    Height = 25
    Top = 86
    Width = 75
    Caption = 'Submit'
    OnClick = btnSubmitClick
    TabOrder = 2
  end
  object StatusBar1: TStatusBar
    Left = 0
    Height = 19
    Top = 146
    Width = 221
    Panels = <>
    SimpleText = 'Please supply login details.'
  end
  object MySQLConnection1: TMySQL50Connection
    Connected = False
    LoginPrompt = False
    KeepConnection = False
    Transaction = SQLTransaction1
    LogEvents = []
    left = 112
    top = 24
  end
  object SQLTransaction1: TSQLTransaction
    Active = False
    Action = caNone
    Database = MySQLConnection1
    left = 152
    top = 24
  end
  object SQLQuery1: TSQLQuery
    Database = MySQLConnection1
    Transaction = SQLTransaction1
    ReadOnly = False
    Params = <>
    left = 192
    top = 24
  end
end

thanks for the help

georgelappies

  • New Member
  • *
  • Posts: 35
Re: My form is blank when it opens now?
« Reply #3 on: July 20, 2011, 11:34:50 am »
Where do you link a unit to a form in the IDE or with code?

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: My form is blank when it opens now?
« Reply #4 on: July 20, 2011, 11:49:33 am »
Where do you link a unit to a form in the IDE or with code?

This information is stored in the LPI project file. A unit without a form is written as:

Code: [Select]
      <Unit7>
        <Filename Value="translationsvmg.pas"/>
        <IsPartOfProject Value="True"/>
        <UnitName Value="translationsvmg"/>
      </Unit7>

And a unit with a form:

Code: [Select]
      <Unit8>
        <Filename Value="configdlg.pas"/>
        <IsPartOfProject Value="True"/>
        <ComponentName Value="ConfigDialog"/>
        <HasResources Value="True"/>
        <ResourceBaseClass Value="Form"/>
        <UnitName Value="configdlg"/>
      </Unit8>

Maybe attaching a zip file with your entire project could help, I haven't seen anything wrong in the pas and lfm

georgelappies

  • New Member
  • *
  • Posts: 35
Re: My form is blank when it opens now?
« Reply #5 on: July 20, 2011, 11:55:25 am »
sure, here is the whole project directory.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: My form is blank when it opens now?
« Reply #6 on: July 20, 2011, 01:24:04 pm »
I've had a go at looking at it. The walkthru form appeared as only the top (title bar) in my IDE. I resized it with the mouse until you could see all controls, saved, recompile, work (okay, after commenting out the various SQL statements that mysteriously didn't work on my MySQL installation  ;)

I did change the version of the MySQL connector and opened it with a newer version of the IDE (Lazarus 0.9.31 from SVN from a couple of days ago).
Still, I can't see anything strange in a diff between your original and my version

Hope the same fix works for you...
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

georgelappies

  • New Member
  • *
  • Posts: 35
Re: My form is blank when it opens now?
« Reply #7 on: July 20, 2011, 01:52:39 pm »
BigChimp

Thanks for your assistance. The form that should load on startup is the login form. When that form opens it just shows blank and no controls. I now cannot get the walkthru form to open on startup at all. I tried resizing but it doesn't fix the login form issue.

George

Zoran

  • Hero Member
  • *****
  • Posts: 1984
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: My form is blank when it opens now?
« Reply #8 on: July 20, 2011, 02:03:07 pm »
I haven't got MySQL installed, but, after commenting out "MySQLConnection.Open" lines from code, I get the login form and it looks okay (Windows 7, Lazarus 0.9.31, fpc 2.4.4).
Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

georgelappies

  • New Member
  • *
  • Posts: 35
Re: My form is blank when it opens now?
« Reply #9 on: July 20, 2011, 02:35:12 pm »
Must be a mysql error then. Weird, I do not recall changing anything between this morning when it worked and later when it stopped working. Haven't touched that form at all.

Thanks all for the help

georgelappies

  • New Member
  • *
  • Posts: 35
Re: My form is blank when it opens now?
« Reply #10 on: July 20, 2011, 02:51:37 pm »
Find the cause of the error! It was an "ID10T" error  :-[ Both forms had on their create property a mysql connection request using the same name on both forms for the TMySQLConnection control. Also the one query hangs when it is executed thus preventing the forms to be created. Took out that code and it works.

Note to self: Never put untested dubious code on a form create or open procedure...

Thanks all for your time.
« Last Edit: July 20, 2011, 04:01:31 pm by georgelappies »

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: [SOLVED] My form is blank when it opens now?
« Reply #11 on: July 21, 2011, 10:37:56 am »
Good that you found the error.

You might also want to look into data modules to store all your connection, transaction objects... Helps to keep an overview of your db connectivity...

(Only just starting with that myself, though)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

 

TinyPortal © 2005-2018