Recent

Author Topic: Labels disappear on TTabSheet  (Read 6810 times)

BezNalogov

  • New Member
  • *
  • Posts: 17
Labels disappear on TTabSheet
« on: August 06, 2009, 08:51:59 pm »
I made a program that uses the TPageControl and in there several TTabSheets and they behave strange after compiling a few times, at first everything worked fine, now it behaves strange.

The tabs are: Login, Contacts, User details and UK.

By default all tabs are not visble, except Login, this is how the program will start.

I didn't make the login procedure yet, so when clicking the login button nothing will be checked and only the contact tab will be activated. However on the login tab no labels are visible at all.

The contact tab works fine, here everything is visible. For certain records also the UK tab will be made visible (this will be done when such record is loaded from the DB).
When I go in this case to the UK tab I see again no labels. When I go back to the contacts tab it gets even more strange: Now even the buttons are not visble anymore. But they are there however, because when I click on such invisible buttons the right action is being commenced.

I develop under Linux, Ubuntu Jaunty to be exact. I use both a 64 bit and 32 bit machine, and this problem appears on both machine.

Also I used before the TNotebook control, here I didn't have this problem, only the TNotebook control doen't have the option to make tabs invisible. So I used the TPageControl.

Does anybody have an idea what this is? Is this a known bug? I couldn't find anything about this in the bug reports.

Here is the code;
Code: [Select]
unit ISysMain;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  Menus, ComCtrls, ExtCtrls, pqconnection, sqldb, db, DbCtrls, Buttons,
  StdCtrls, rxlookup, dbdateedit, LCLType;

type

  { TFrmIsysMain }

  TFrmIsysMain = class(TForm)
    BtnLogin: TBitBtn;
    Datasource1: TDatasource;
    Datasource2: TDatasource;
    Datasource3: TDatasource;
    Datasource4: TDatasource;
    Datasource5: TDatasource;
    FldLogin: TEdit;
    FldPassword: TEdit;
    FldAR: TDBDateEdit;
    DBDateEdit2: TDBDateEdit;
    DBDateEdit3: TDBDateEdit;
    FldDOI: TDBDateEdit;
    FldCompanynumber: TDBEdit;
    FldAuthcode: TDBEdit;
    FldLoginActive: TDBCheckBox;
    FldCompanyname: TDBEdit;
    FldUsername: TDBEdit;
    FldAddress1: TDBEdit;
    FldFax: TDBEdit;
    FldPostalcode: TDBEdit;
    FldAddress2: TDBEdit;
    FldCity: TDBEdit;
    FldCounty: TDBEdit;
    FldEmail: TDBEdit;
    FldTelephone: TDBEdit;
    FldGSM: TDBEdit;
    FldFirstname: TDBEdit;
    FldOthernames: TDBEdit;
    Label1: TLabel;
    Label10: TLabel;
    GSM: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Label2: TLabel;
    Label20: TLabel;
    Label21: TLabel;
    Label22: TLabel;
    Label23: TLabel;
    Label24: TLabel;
    Label25: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    FldExtensionID: TRxDBLookupCombo;
    FldStatusID: TRxDBLookupCombo;
    BtnResetPassword: TSpeedButton;
    BtnUKCancel: TSpeedButton;
    BtnUKUpdate: TSpeedButton;
    Panel1: TPanel;
    FldCountry: TRxDBLookupCombo;
    SQLExtensions: TSQLQuery;
    SQLJurisdictions: TSQLQuery;
    SQLUK: TSQLQuery;
    SQLStatus: TSQLQuery;
    TabUK: TTabSheet;
    TabUserDetails: TTabSheet;
    TxtSearch: TEdit;
    FldName: TDBEdit;
    MnuMain: TMainMenu;
    MnuFile: TMenuItem;
    MopQuit: TMenuItem;
    MnuContacts: TMenuItem;
    MopNewContact: TMenuItem;
    Notebook1: TPageControl;
    PQDB: TPQConnection;
    BtnNext: TSpeedButton;
    BtnPrevious: TSpeedButton;
    BtnDelete: TSpeedButton;
    BtnUpdate: TSpeedButton;
    BtnAppend: TSpeedButton;
    BtnLast: TSpeedButton;
    BtnFirst: TSpeedButton;
    BtnCancel: TSpeedButton;
    BtnEdit: TSpeedButton;
    BtnSearch: TSpeedButton;
    SQLContacts: TSQLQuery;
    SQLTransaction1: TSQLTransaction;
    TabContacts: TTabSheet;
    TabLogin: TTabSheet;
    Statusbar: TStatusBar;
    procedure BtnAppendClick(Sender: TObject);
    procedure BtnCancelClick(Sender: TObject);
    procedure BtnDeleteClick(Sender: TObject);
    procedure BtnFirstClick(Sender: TObject);
    procedure BtnLastClick(Sender: TObject);
    procedure BtnLoginClick(Sender: TObject);
    procedure BtnNextClick(Sender: TObject);
    procedure BtnPreviousClick(Sender: TObject);
    procedure BtnSearchClick(Sender: TObject);
    procedure BtnUpdateClick(Sender: TObject);
    procedure FldCompanynameChange(Sender: TObject);
    procedure FldCompanynameExit(Sender: TObject);
    procedure FldNameExit(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure MopQuitClick(Sender: TObject);
    procedure Notebook1Enter(Sender: TObject);
    procedure TabUKEnter(Sender: TObject);
    procedure CheckRecord;
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  FrmIsysMain: TFrmIsysMain;

implementation

{ TFrmIsysMain }

procedure TFrmIsysMain.CheckRecord;
begin
  if(SQLContacts.Fields.FieldByName('companyname').AsString <> '') then
   begin
    FldName.Enabled:=FALSE;
    FldFirstname.Enabled:=FALSE;
    FldOthernames.Enabled:=FALSE;
    FldEmail.Enabled:=FALSE;
    FldGSM.Enabled:=FALSE;
    FldTelephone.Enabled:=FALSE;
    FldFax.Enabled:=FALSE;
    FldCompanyname.Enabled:=TRUE;
    FldExtensionID.Enabled:=TRUE;
    if(SQLContacts.FieldByName('jurisdiction_id').AsInteger = 1) then
      TabUK.TabVisible := TRUE;
   end
  else
   begin
    FldName.Enabled:=TRUE;
    FldFirstname.Enabled:=TRUE;
    FldOthernames.Enabled:=TRUE;
    FldEmail.Enabled:=TRUE;
    FldGSM.Enabled:=TRUE;
    FldTelephone.Enabled:=TRUE;
    FldFax.Enabled:=TRUE;
    FldCompanyname.Enabled:=FALSE;
    FldExtensionID.Enabled:=FALSE;
    TabUK.TabVisible := FALSE;
   end;
end;

procedure TFrmIsysMain.BtnNextClick(Sender: TObject);
var result: integer;
begin
  if(BtnUpdate.Enabled = TRUE) then
  begin
   with Application do begin
     result := MessageBox('Save changes?',
                          'Confirmation',
                          MB_ICONQUESTION + MB_YESNO);
     if (result = ID_OK) then BtnUpdate.Click
     else BtnCancel.Click;
   end;
  end;


  SQLContacts.Next;
  BtnCancel.Enabled := FALSE;
  BtnUpdate.Enabled := FALSE;
  CheckRecord;
end;

procedure TFrmIsysMain.BtnDeleteClick(Sender: TObject);
var
  contact_id,sql: string;
  result: integer;
begin
  contact_id := SQLContacts.Fields.FieldByName('contact_id').AsString;
  sql := 'DELETE FROM is_contacts WHERE contact_id = ' +
          contact_id;
  with Application do begin
    result := MessageBox('Are you sure you want to delete this record?',
                         'Confirmation',
                         MB_ICONQUESTION + MB_YESNO);
    if(result = ID_YES) then
     begin
      PQDB.ExecuteDirect('Begin work;');
      PQDB.ExecuteDirect(sql);
      PQDB.ExecuteDirect('Commit work;');
      SQLContacts.Close;
      SQLContacts.Open;
      Statusbar.Simpletext := 'Record deleted';
      CheckRecord;
     end;
  end;
end;

procedure TFrmIsysMain.BtnFirstClick(Sender: TObject);
var result: integer;
begin
  if(BtnUpdate.Enabled = TRUE) then
  begin
   with Application do begin
     result := MessageBox('Save changes?',
                          'Confirmation',
                          MB_ICONQUESTION + MB_YESNO);
     if (result = ID_OK) then BtnUpdate.Click
     else BtnCancel.Click;
   end;
  end;

  SQLContacts.First;
  BtnCancel.Enabled := FALSE;
  BtnUpdate.Enabled := FALSE;
  CheckRecord;
end;

procedure TFrmIsysMain.BtnLastClick(Sender: TObject);
var result: integer;
begin
  if(BtnUpdate.Enabled = TRUE) then
  begin
   with Application do begin
     result := MessageBox('Save changes?',
                          'Confirmation',
                          MB_ICONQUESTION + MB_YESNO);
     if (result = ID_OK) then BtnUpdate.Click
     else BtnCancel.Click;
   end;
  end;


  SQLContacts.Last;
  BtnCancel.Enabled := FALSE;
  BtnUpdate.Enabled := FALSE;
  CheckRecord;
end;

procedure TFrmIsysMain.BtnLoginClick(Sender: TObject);
begin
  TabContacts.TabVisible := True;
  TabLogin.TabVisible := False;
end;

procedure TFrmIsysMain.BtnAppendClick(Sender: TObject);
begin
  SQLContacts.Append;
  SQLContacts.FieldByName('extension_id').Value := 1;
  SQLContacts.FieldByName('status_id').Value := 1;
  SQLContacts.FieldByName('login_active').Value := FALSE;
  (* SQLContacts.ApplyUpdates; *)
  Statusbar.Simpletext := 'Record appended';
end;

procedure TFrmIsysMain.BtnCancelClick(Sender: TObject);
begin
  SQLContacts.Cancel;
  BtnUpdate.Enabled := FALSE;
  BtnCancel.Enabled := FALSE;
  Statusbar.SimpleText:='Changed cancelled';
  CheckRecord;
end;

procedure TFrmIsysMain.BtnPreviousClick(Sender: TObject);
var result: integer;
begin
  if(BtnUpdate.Enabled = TRUE) then
  begin
   with Application do begin
     result := MessageBox('Save changes?',
                          'Confirmation',
                          MB_ICONQUESTION + MB_YESNO);
     if (result = ID_OK) then BtnUpdate.Click
     else BtnCancel.Click;
   end;
  end;

  SQLContacts.Prior;
  BtnCancel.Enabled := FALSE;
  BtnUpdate.Enabled := FALSE;
  CheckRecord;
end;

procedure TFrmIsysMain.BtnSearchClick(Sender: TObject);
begin
  SQLContacts.Close;

  if (TxtSearch.Text = '') then
    SQLContacts.SQL.Text := 'SELECT * FROM is_contacts'
  else
    SQLContacts.SQL.Text := 'SELECT * FROM is_contacts ' +
                             'WHERE name ~* ''' +
                             TxtSearch.Text + '''';
  if (SQLContacts.Active = FALSE) then SQLContacts.Active := TRUE;
  SQLContacts.Open;

  SQLExtensions.Active:= TRUE;
  SQLStatus.Active:= TRUE;
  SQLJurisdictions.Active := TRUE;

  BtnFirst.Enabled := TRUE;
  BtnPrevious.Enabled := TRUE;
  BtnNext.Enabled := TRUE;
  BtnLast.Enabled := TRUE;
  BtnAppend.Enabled := TRUE;
  BtnDelete.Enabled := TRUE;
  BtnCancel.Enabled := FALSE;
  BtnUpdate.Enabled := FALSE;
  CheckRecord;
  Statusbar.Simpletext := 'Record(s) loaded';
end;

procedure TFrmIsysMain.BtnUpdateClick(Sender: TObject);
var contact_id,extension_id,login_active,sql: string;
begin
  SQLContacts.ApplyUpdates;

  if(SQLContacts.Fields.FieldByName('login_active').AsBoolean = TRUE) then
    login_active := 'TRUE'
  else
    login_active := 'FALSE';

  if(SQLContacts.Fields.FieldByName('extension_id').AsString = '') then
    extension_id := '1'
  else
    extension_id := SQLContacts.Fields.FieldByName('extension_id').AsString;

  if (SQLContacts.Fields.FieldByName('contact_id').AsString <> '') then
  begin
    contact_id := SQLContacts.Fields.FieldByName('contact_id').AsString;

    sql := 'UPDATE is_contacts SET ' +
           'name = ''' +
           SQLContacts.Fields.FieldByName('name').AsString + ''',' +
           'firstname = ''' +
           SQLContacts.Fields.FieldByName('firstname').AsString + ''',' +
           'othernames = ''' +
           SQLContacts.Fields.FieldByName('othernames').AsString + ''',' +
           'address1 = ''' +
           SQLContacts.Fields.FieldByName('address1').AsString + ''',' +
           'address2 = ''' +
           SQLContacts.Fields.FieldByName('address2').AsString + ''',' +
           'postalcode = ''' +
           SQLContacts.Fields.FieldByName('postalcode').AsString + ''',' +
           'city = ''' +
           SQLContacts.Fields.FieldByName('city').AsString + ''',' +
           'county = ''' +
           SQLContacts.Fields.FieldByName('county').AsString + ''',' +
           'jurisdiction_id = ''' +
           SQLContacts.Fields.FieldByName('jurisdiction_id').AsString + ''',' +
           'email = ''' +
           SQLContacts.Fields.FieldByName('email').AsString + ''',' +
           'telephone = ''' +
           SQLContacts.Fields.FieldByName('telephone').AsString + ''',' +
           'gsm = ''' +
           SQLContacts.Fields.FieldByName('gsm').AsString + ''',' +
           'fax = ''' +
           SQLContacts.Fields.FieldByName('fax').AsString + ''',' +
           'companyname = ''' +
           SQLContacts.Fields.FieldByName('companyname').AsString + ''',' +
           'extension_id = ' +
           extension_id + ',' +
           'login = ''' +
           SQLContacts.Fields.FieldByName('login').AsString + ''',' +
           'login_active = ''' +
           login_active + ''',' +
           'status_id = ' +
           SQLContacts.Fields.FieldByName('status_id').AsString + ' ' +
           'WHERE contact_id = ' + contact_id;
   end
  else
    sql := 'INSERT INTO is_contacts ' +
           '(name,firstname,othernames,address1,address2,postalcode,city,' +
           'county,jurisdiction_id,email,telephone,gsm,fax,companyname,extension_id,' +
           'login,status_id,login_active) VALUES(' +
           '''' + SQLContacts.Fields.FieldByName('name').AsString + ''',' +
           '''' + SQLContacts.Fields.FieldByName('firstname').AsString + ''',' +
           '''' + SQLContacts.Fields.FieldByName('othernames').AsString + ''',' +
           '''' + SQLContacts.Fields.FieldByName('address1').AsString + ''',' +
           '''' + SQLContacts.Fields.FieldByName('address2').AsString + ''',' +
           '''' + SQLContacts.Fields.FieldByName('postalcode').AsString + ''',' +
           '''' + SQLContacts.Fields.FieldByName('city').AsString + ''',' +
           '''' + SQLContacts.Fields.FieldByName('county').AsString + ''',' +
           '''' + SQLContacts.Fields.FieldByName('jurisdiction_id').AsString + ''',' +
           '''' + SQLContacts.Fields.FieldByName('email').AsString + ''',' +
           '''' + SQLContacts.Fields.FieldByName('telephone').AsString + ''',' +
           '''' + SQLContacts.Fields.FieldByName('gsm').AsString + ''',' +
           '''' + SQLContacts.Fields.FieldByName('fax').AsString + ''',' +
           '''' + SQLContacts.Fields.FieldByName('companyname').AsString + ''',' +
                  extension_id + ',' +
           '''' + SQLContacts.Fields.FieldByName('login').AsString + ''',' +
                  SQLContacts.Fields.FieldByName('status_id').AsString + ',' +
           '''' + login_active + ''')';

  PQDB.ExecuteDirect('Begin work;');
  PQDB.ExecuteDirect(sql);
  PQDB.ExecuteDirect('Commit work;');
  SQLContacts.Close;
  SQLContacts.Open;
  BtnCancel.Enabled := FALSE;
  BtnUpdate.Enabled := FALSE;
  CheckRecord;
  Statusbar.SimpleText:='Record saved';
end;

procedure TFrmIsysMain.FldCompanynameChange(Sender: TObject);
begin
  if (BtnUpdate.Enabled = FALSE) then BtnUpdate.Enabled := TRUE;
  if (BtnCancel.Enabled = FALSE) then BtnCancel.Enabled := TRUE;
end;

procedure TFrmIsysMain.FldCompanynameExit(Sender: TObject);
begin
  if(FldCompanyname.Text = '') then
   begin
    FldName.Enabled:=TRUE;
    FldFirstname.Enabled:=TRUE;
    FldOthernames.Enabled:=TRUE;
    FldEmail.Enabled:=TRUE;
    FldGSM.Enabled:=TRUE;
    FldTelephone.Enabled:=TRUE;
    FldFax.Enabled:=TRUE;
   end
  else
   begin
    FldName.Enabled:=FALSE;
    FldName.Text:= '';

    FldFirstname.Enabled:=FALSE;
    FldFirstname.Text:= '';

    FldOthernames.Enabled:=FALSE;
    FldOthernames.Text:= '';

    FldEmail.Enabled:=FALSE;
    FldEmail.Text:= '';

    FldGSM.Enabled:=FALSE;
    FldGSM.Text:= '';

    FldTelephone.Enabled:=FALSE;
    FldTelephone.Text:= '';

    FldFax.Enabled:=FALSE;
    FldFax.Text:= '';
   end;
end;

procedure TFrmIsysMain.FldNameExit(Sender: TObject);
begin
  if(FldName.Text = '') then
   begin
    FldCompanyname.Enabled:=TRUE;
    FldExtensionID.Enabled:=TRUE;
   end
  else
   begin
    FldCompanyname.Enabled:=FALSE;
    FldCompanyname.Text:='';

    FldExtensionID.Enabled:=FALSE;
   end;

end;

procedure TFrmIsysMain.FormCreate(Sender: TObject);
begin

end;

procedure TFrmIsysMain.MopQuitClick(Sender: TObject);
begin
  Close;
end;

procedure TFrmIsysMain.Notebook1Enter(Sender: TObject);
begin

end;

procedure TFrmIsysMain.TabUKEnter(Sender: TObject);
begin
  SQLUK.Close;
  SQLUK.SQL.Text := 'SELECT * FROM is_uk WHERE contact_id = ' +
                    SQLContacts.Fields.FieldByName('contact_id').AsString;
  SQLUK.Open;
end;


initialization
  {$I isysmain.lrs}

end.
« Last Edit: August 06, 2009, 08:57:52 pm by Vincent Snijders »

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Re: Labels disappear on TTabSheet
« Reply #1 on: August 06, 2009, 08:59:19 pm »
I put the code in a [ code ] tag.

BezNalogov

  • New Member
  • *
  • Posts: 17
Re: Labels disappear on TTabSheet
« Reply #2 on: August 06, 2009, 09:01:09 pm »

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: Labels disappear on TTabSheet
« Reply #3 on: August 06, 2009, 09:02:20 pm »

BezNalogov

  • New Member
  • *
  • Posts: 17
Re: Labels disappear on TTabSheet
« Reply #4 on: August 07, 2009, 10:23:29 am »
Yes, except that it doesn't just happen on the first tab, also on the third tab as soon as it's being made visible.

Is there a workaround for this?

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: Labels disappear on TTabSheet
« Reply #5 on: August 07, 2009, 11:24:48 am »
I don't know I can't reproduce the problem now.

Can you make a full project (with form) which shows the problem, but has no extra stuff lke database etc. in it? Just the PageControl showing the problem?

If it is reproducible, then maybe somebody can have a look at it.

BezNalogov

  • New Member
  • *
  • Posts: 17
Re: Labels disappear on TTabSheet
« Reply #6 on: August 08, 2009, 01:14:57 pm »
Yes, np, I'll make that

BezNalogov

  • New Member
  • *
  • Posts: 17
Re: Labels disappear on TTabSheet
« Reply #7 on: August 08, 2009, 09:55:47 pm »
I switched for another problem to the GTK2 version, now this problem is also solved.

 

TinyPortal © 2005-2018