On a form I have 8 edit boxes that I do the exact same thing with.
They are arranged in 2 sets of 4, one is Upper and the other is Lower.
I kept getting errors clearing all the edit boxes so I went through clearing them 1 by 1 and found that 1 of the edit boxes just didnt work and when I tried to run the program and change that exit box it caused the debugger to jump to a point in the code with the database (even though the edit boxes had nothing to do with the database and they arent in a procedure or stack with a database in it) and say the program has access violation there.
So I then removed all mention of that edit box and the code worked perfectly again, so I deleted that edit box, copied and pasted another edit box and left all values the same, then went through my code and copied the code from the other sections and simply renamed it for the new Edit box and it STILL causes an error even though it is entirely new.
I cannot figure it out so I ask you all, what the hell?
The editbox in question is "Edit1"
unit DefinitionCoreV2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, SQLiteTable3, StdCtrls;
type
TDefinitionFrm = class(TForm)
GrpCompetition: TGroupBox;
CmbCompSele: TComboBox;
BtnCompetitionAdd: TButton;
BtnCompetitionUpdate: TButton;
BtnCompetitionRevert: TButton;
GrpCompetitionDetails: TGroupBox;
LblCompetitionIDTitle: TLabel;
EdtCompID: TEdit;
LblCompetitionDescriptionTitle: TLabel;
EdtCompDesc: TEdit;
LblCompetitionNotesTitle: TLabel;
EdtCompNote: TEdit;
LblCompetitionLocationTitle: TLabel;
EdtCompLoca: TEdit;
BtnCompetitionDelete: TButton;
GrpSection: TGroupBox;
LblSectionID: TLabel;
LblGender: TLabel;
LblAge: TLabel;
LblLevel: TLabel;
LblWeight: TLabel;
LblType: TLabel;
LblHeight: TLabel;
LblCompetitionID: TLabel;
BtnSectionAdd: TButton;
EdtSectionID: TEdit;
CmbGender: TComboBox;
BtnSectionUpdate: TButton;
BtnSectionRevert: TButton;
CmbAgeRange: TComboBox;
CmbLevelRange: TComboBox;
CmbType: TComboBox;
CmbWeightRange: TComboBox;
CmbHeightRange: TComboBox;
EdtSectCompetitionID: TEdit;
BtnSectionDelete: TButton;
GrpSectionDetails: TGroupBox;
EdtLowerAge: TEdit;
EdtLowerWeight: TEdit;
EdtLowerHeight: TEdit;
EdtUpperAge: TEdit;
EdtUpperLevel: TEdit;
EdtUpperWeight: TEdit;
EdtUpperHeight: TEdit;
LblAgeRule: TLabel;
LblLevelRule: TLabel;
LblWeightRule: TLabel;
LblHeightRule: TLabel;
LblCompetitionSelect: TLabel;
LblSectionSelect: TLabel;
CmbSectSele: TComboBox;
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
procedure BtnCompetitionAddClick(Sender: TObject);
procedure CmbCompSeleChange(Sender: TObject);
procedure BtnCompetitionUpdateClick(Sender: TObject);
procedure BtnCompetitionRevertClick(Sender: TObject);
procedure BtnCompetitionDeleteClick(Sender: TObject);
procedure CmbSectSeleChange(Sender: TObject);
procedure BtnSectionAddClick(Sender: TObject);
procedure BtnSectionUpdateClick(Sender: TObject);
procedure BtnSectionRevertClick(Sender: TObject);
procedure BtnSectionDeleteClick(Sender: TObject);
procedure CmbAgeRangeChange(Sender: TObject);
procedure CmbLevelRangeChange(Sender: TObject);
procedure CmbWeightRangeChange(Sender: TObject);
procedure CmbHeightRangeChange(Sender: TObject);
private
procedure UpdateCmbCompSele;
procedure AddComp;
procedure RevertComp;
procedure AddSect;
procedure RevertSect;
procedure UpdateCmbSectSele;
procedure ClearSect;
{ Private declarations }
public
{ Public declarations }
end;
var
DefinitionFrm: TDefinitionFrm;
implementation
{$R *.dfm}
procedure TDefinitionFrm.UpdateCmbCompSele;
var
slDBpath: string;
sldb : TSQLiteDatabase;
sltb : TSQLiteTable;
sCompTitle : string;
bNext : boolean;
begin
slDBPath := ExtractFilepath(application.exename)+ 'Competitions.db';
if not FileExists(slDBPath) then
begin
MessageDlg('Competitions.db does not exist.',mtInformation,[mbOK],0);
exit;
end;
sldb := TSQLiteDatabase.Create(slDBPath);
try
sltb := slDb.GetTable('SELECT * FROM CompetitionTable');
try
CmbCompSele.Items.Clear;
Repeat
begin
sCompTitle:=sltb.FieldAsString(sltb.FieldIndex['CompetitionID'])+':'+sltb.FieldAsString(sltb.FieldIndex['Description']);
CmbCompSele.Items.Add(sCompTitle);
bNext := sltb.Next;
end;
Until sltb.EOF;
finally
sltb.Free;
end;
finally
sldb.Free;
end;
end;
procedure TDefinitionFrm.UpdateCmbSectSele;
var
slDBpath: string;
sldb : TSQLiteDatabase;
sltb : TSQLiteTable;
sSQL : string;
sSectTitle : string;
bNext : boolean;
bLast : boolean;
begin
slDBPath := ExtractFilepath(application.exename)+ 'Competitions.db';
if not FileExists(slDBPath) then
begin
MessageDlg('Competitions.db does not exist.',mtInformation,[mbOK],0);
exit;
end;
sldb := TSQLiteDatabase.Create(slDBPath);
try
sltb := slDb.GetTable('SELECT * FROM SectionTable WHERE CompetitionID = '+EdtCompID.text);
If sltb.RowCount =0 then
begin
sltb := slDb.GetTable('SELECT * FROM SectionTable');
bLast:= sltb.MoveLast;
sSQL := 'INSERT INTO SectionTable(SectionID,CompetitionID,Gender,Type) VALUES ('+IntToStr(sltb.FieldAsInteger(sltb.FieldIndex['SectionID'])+1)+','+EdtCompID.text+',1,1)';
sldb.ExecSQL(sSQL);
sltb := slDb.GetTable('SELECT * FROM SectionTable WHERE CompetitionID = '+EdtCompID.text);
end;
try
CmbSectSele.Items.Clear;
Repeat
begin
sSectTitle:=sltb.FieldAsString(sltb.FieldIndex['SectionID'])+':'+sltb.FieldAsString(sltb.FieldIndex['Type'])+':'+sltb.FieldAsString(sltb.FieldIndex['Gender'])+':'+sltb.FieldAsString(sltb.FieldIndex['Age'])+':'+sltb.FieldAsString(sltb.FieldIndex['Level'])+':'+sltb.FieldAsString(sltb.FieldIndex['Weight'])+':'+sltb.FieldAsString(sltb.FieldIndex['Height']);
CmbSectSele.Items.Add(sSectTitle); //CmbType.Items.Strings[sltb.FieldAsInteger(sltb.FieldIndex['Type'])] Works but has logic errors
bNext := sltb.Next;
end;
Until sltb.EOF;
finally
sltb.Free;
end;
finally
sldb.Free;
end;
end;
procedure TDefinitionFrm.AddComp;
var
slDBpath: string;
sSQL : string;
sldb : TSQLiteDatabase;
sltb : TSQLiteTable;
bLast : boolean;
begin
slDBPath := ExtractFilepath(application.exename)+ 'Competitions.db';
if not FileExists(slDBPath) then
begin
MessageDlg('Competitions.db does not exist.',mtInformation,[mbOK],0);
exit;
end;
sldb := TSQLiteDatabase.Create(slDBPath);
try
sltb := slDb.GetTable('SELECT * FROM CompetitionTable');
try
bLast:= sltb.MoveLast;
sSQL := 'INSERT INTO CompetitionTable(CompetitionID,Description) VALUES ('+IntToStr(sltb.FieldAsInteger(sltb.FieldIndex['CompetitionID'])+1)+',"New Competition")';
sldb.ExecSQL(sSQL);
finally
sltb.Free;
end;
finally
sldb.Free;
end;
UpdateCmbCompSele;
end;
procedure TDefinitionFrm.AddSect;
var
slDBpath: string;
sSQL : string;
sldb : TSQLiteDatabase;
sltb : TSQLiteTable;
bLast : boolean;
begin
slDBPath := ExtractFilepath(application.exename)+ 'Competitions.db';
if not FileExists(slDBPath) then
begin
MessageDlg('Competitions.db does not exist.',mtInformation,[mbOK],0);
exit;
end;
sldb := TSQLiteDatabase.Create(slDBPath);
try
sltb := slDb.GetTable('SELECT * FROM SectionTable');
try
bLast:= sltb.MoveLast;
sSQL := 'INSERT INTO SectionTable(SectionID,CompetitionID,Gender,Type) VALUES ('+IntToStr(sltb.FieldAsInteger(sltb.FieldIndex['SectionID'])+1)+','+EdtCompID.text+',1,1)';
sldb.ExecSQL(sSQL);
finally
sltb.Free;
end;
finally
sldb.Free;
end;
UpdateCmbSectSele;
end;
procedure TDefinitionFrm.RevertComp;
var
slDBpath: string;
sldb : TSQLiteDatabase;
sltb : TSQLiteTable;
iID : integer;
begin
slDBPath := ExtractFilepath(application.exename)+ 'Competitions.db';
if not FileExists(slDBPath) then
begin
MessageDlg('Competitions.db does not exist.',mtInformation,[mbOK],0);
exit;
end;
sldb := TSQLiteDatabase.Create(slDBPath);
try
If CmbCompSele.Text <> '' then
begin
iID := StrToInt(Copy(CmbCompSele.Text,0,Pos(':',CmbCompSele.Text)-1));
sltb := slDb.GetTable('SELECT * FROM CompetitionTable WHERE CompetitionID='+IntToStr(iID))//ItemIndex starts at 0, CompID at 1
end
else
sltb := slDb.GetTable('SELECT * FROM CompetitionTable WHERE CompetitionID=1');
try
EdtCompID.Text:=sltb.FieldAsString(sltb.FieldIndex['CompetitionID']);
EdtCompLoca.Text:=sltb.FieldAsString(sltb.FieldIndex['Location']);
EdtCompDesc.Text:=sltb.FieldAsString(sltb.FieldIndex['Description']);
EdtCompNote.Text:=sltb.FieldAsString(sltb.FieldIndex['Notes']);
finally
sltb.Free;
end;
finally
sldb.Free;
end;
end;
procedure TDefinitionFrm.RevertSect;
var
slDBpath: string;
sldb : TSQLiteDatabase;
sltb : TSQLiteTable;
iID : integer;
sTemp : string;
begin
slDBPath := ExtractFilepath(application.exename)+ 'Competitions.db';
if not FileExists(slDBPath) then
begin
MessageDlg('Competitions.db does not exist.',mtInformation,[mbOK],0);
exit;
end;
sldb := TSQLiteDatabase.Create(slDBPath);
try
If CmbCompSele.Text <> '' then
begin
iID := StrToInt(Copy(CmbSectSele.Text,0,Pos(':',CmbSectSele.Text)-1));
sltb := slDb.GetTable('SELECT * FROM SectionTable WHERE SectionID='+IntToStr(iID));//ItemIndex starts at 0, CompID at 1
end
else
sltb := slDb.GetTable('SELECT * FROM SectionTable WHERE CompetitionID='+EdtCompID.Text);
try
EdtSectionID.Text:=sltb.FieldAsString(sltb.FieldIndex['SectionID']);
EdtSectCompetitionID.Text:=sltb.FieldAsString(sltb.FieldIndex['CompetitionID']);
Case sltb.FieldAsInteger(sltb.FieldIndex['Type']) of
1 : CmbType.ItemIndex:=0;
2 : CmbType.ItemIndex:=0;
3 : CmbType.ItemIndex:=1;
4 : CmbType.ItemIndex:=1;
end;
Case sltb.FieldAsInteger(sltb.FieldIndex['Gender']) of
1 : CmbGender.ItemIndex:=0;
2 : CmbGender.ItemIndex:=1;
3 : CmbGender.ItemIndex:=2;
end;
sTemp := sltb.FieldAsString(sltb.FieldIndex['Age']);
if sTemp <> '' then
begin
//Decode
end
else
begin
LblAgeRule.Hide;
EdtLowerAge.Text :='';
EdtLowerAge.Hide;
EdtUpperAge.Text :='';
EdtUpperAge.Hide;
end;
sTemp := sltb.FieldAsString(sltb.FieldIndex['Level']);
if sTemp <> '' then
begin
//Decode
end
else
begin
LblLevelRule.Hide;
Edit1.Text :='';
Edit1.Hide;
EdtUpperLevel.Text :='';
EdtUpperLevel.Hide;
end;
sTemp := sltb.FieldAsString(sltb.FieldIndex['Weight']);
if sTemp <> '' then
begin
//Decode
end
else
begin
LblWeightRule.Hide;
EdtLowerWeight.Text :='';
EdtLowerWeight.Hide;
EdtUpperWeight.Text :='';
EdtUpperWeight.Hide;
end;
sTemp := sltb.FieldAsString(sltb.FieldIndex['Height']);
if sTemp <> '' then
begin
//Decode
end
else
begin
LblHeightRule.Hide;
EdtLowerHeight.Text :='';
EdtLowerHeight.Hide;
EdtUpperHeight.Text :='';
EdtUpperHeight.Hide;
end;
finally
sltb.Free;
end;
finally
sldb.Free;
end;
end;
procedure TDefinitionFrm.BtnCompetitionAddClick(Sender: TObject);
begin
AddComp
end;
procedure TDefinitionFrm.ClearSect;
begin
CmbSectSele.Clear;
EdtSectionID.Text:='';
EdtSectCompetitionID.Text:='';
CmbType.Clear;
CmbGender.Clear;
CmbAgeRange.Clear;
EdtLowerAge.Text:='';
EdtUpperAge.Text:='';
CmbLevelRange.Clear;
Edit1.Text:='';
EdtUpperLevel.Text:='';
CmbWeightRange.Clear;
EdtLowerWeight.Text:='';
EdtUpperWeight.Text:='';
CmbHeightRange.Clear;
EdtLowerHeight.Text:='';
EdtUpperHeight.Text:='';
end;
procedure TDefinitionFrm.CmbCompSeleChange(Sender: TObject);
begin
If CmbCompSele.ItemIndex <> -1 then
begin
RevertComp;
GrpSection.Enabled:=True;
CmbSectSele.Clear;
ClearSect;
UpdateCmbSectSele;
end;
end;
procedure TDefinitionFrm.BtnCompetitionUpdateClick(Sender: TObject);
var
slDBpath: string;
sSQL : string;
sldb : TSQLiteDatabase;
begin
slDBPath := ExtractFilepath(application.exename)+ 'Competitions.db';
if not FileExists(slDBPath) then
begin
MessageDlg('Competitions.db does not exist.',mtInformation,[mbOK],0);
exit;
end;
sldb := TSQLiteDatabase.Create(slDBPath);
try
sSQL:= 'UPDATE CompetitionTable SET Description="'+EdtCompDesc.Text+'",Location="'+EdtCompLoca.Text+'",Notes="'+EdtCompNote.Text+'" WHERE CompetitionID ="'+EdtCompID.Text+'";';
sldb.ExecSQL(sSQL);
finally
sldb.Free;
end;
end;
procedure TDefinitionFrm.BtnCompetitionRevertClick(Sender: TObject);
begin
RevertComp;
end;
procedure TDefinitionFrm.BtnCompetitionDeleteClick(Sender: TObject);
var
slDBpath: string;
sSQL : string;
sldb : TSQLiteDatabase;
iID : integer;
begin
If CmbCompSele.Text <> '' then
begin
If (CmbCompSele.Text[1] ='1') and (CmbCompSele.Text[2] =':') then
begin
MessageDlg('Deleting the last record is a very bad idea :/',mtInformation,[mbOK],0);
end
else
begin
slDBPath := ExtractFilepath(application.exename)+ 'Competitions.db';
if not FileExists(slDBPath) then
begin
MessageDlg('Competitions.db does not exist.',mtInformation,[mbOK],0);
exit;
end;
sldb := TSQLiteDatabase.Create(slDBPath);
try
iID := StrToInt(Copy(CmbCompSele.Text,0,Pos(':',CmbCompSele.Text)-1));
sSQL:= 'DELETE FROM SectionTable WHERE CompetitionID='+IntToStr(iID)+';';
sldb.ExecSQL(sSQL);
sSQL:= 'DELETE FROM CompetitionTable WHERE CompetitionID='+IntToStr(iID)+';';
sldb.ExecSQL(sSQL);
finally
sldb.Free;
end;
CmbCompSele.ItemIndex:=0;
UpdateCmbCompSele;
RevertComp;
CmbCompSele.Text:='Select Competition';
end;
end;
end;
procedure TDefinitionFrm.FormCreate(Sender: TObject);
begin
UpdateCmbCompSele;
end;
procedure TDefinitionFrm.CmbSectSeleChange(Sender: TObject);
begin
RevertSect;
end;
procedure TDefinitionFrm.BtnSectionAddClick(Sender: TObject);
begin
AddSect;
end;
procedure TDefinitionFrm.BtnSectionUpdateClick(Sender: TObject); //change fields values
var
slDBpath: string;
sSQL : string;
sldb : TSQLiteDatabase;
iTypeCode : integer;
iGenderCode : integer;
sAgeStr,
sLevelStr,
sWeightStr,
sHeightStr : string;
begin
slDBPath := ExtractFilepath(application.exename)+ 'Competitions.db';
if not FileExists(slDBPath) then
begin
MessageDlg('Competitions.db does not exist.',mtInformation,[mbOK],0);
exit;
end;
sldb := TSQLiteDatabase.Create(slDBPath);
try
If CmbType.Text='Fighting' then
iTypeCode := 1
else
iTypeCode := 3;
If CmbGender.Text='Male' then
iGenderCode := 1
else if CmbGender.Text='Female' then
iGenderCode := 2
else
iGenderCode := 3;
Case CmbAgeRange.ItemIndex of
0:sAgeStr := 'o-'+EdtLowerAge.Text;
1:sAgeStr := 'u-'+EdtLowerAge.Text;
2:sAgeStr := EdtLowerAge.Text+'-'+EdtUpperAge.Text;
end;
Case CmbLevelRange.ItemIndex of
0:sLevelStr := 'o-'+Edit1.Text;
1:sLevelStr := 'u-'+Edit1.Text;
2:sLevelStr := Edit1.Text+'-'+EdtUpperLevel.Text;
end;
Case CmbWeightRange.ItemIndex of
0:sWeightStr := 'o-'+EdtLowerWeight.Text;
1:sWeightStr := 'u-'+EdtLowerWeight.Text;
2:sWeightStr := EdtLowerWeight.Text+'-'+EdtUpperWeight.Text;
end;
Case CmbHeightRange.ItemIndex of
0:sHeightStr := 'o-'+EdtLowerHeight.Text;
1:sHeightStr := 'u-'+EdtLowerHeight.Text;
2:sHeightStr := EdtLowerHeight.Text+'-'+EdtUpperHeight.Text;
end;
sSQL:= 'UPDATE SectionTable SET Type="'+IntToStr(iTypeCode)+'",Gender="'+IntToStr(iGenderCode)+'" WHERE SectionID ="'+EdtSectionID.Text+'";';
sldb.ExecSQL(sSQL);
finally
sldb.Free;
end;
end;
procedure TDefinitionFrm.BtnSectionRevertClick(Sender: TObject);
begin
RevertSect;
end;
procedure TDefinitionFrm.BtnSectionDeleteClick(Sender: TObject);
var
slDBpath: string;
sSQL : string;
sldb : TSQLiteDatabase;
begin
If CmbSectSele.Text[1] ='1' then
begin
MessageDlg('Deleting the last record is a very bad idea :/',mtInformation,[mbOK],0);
end
else
begin
slDBPath := ExtractFilepath(application.exename)+ 'Competitions.db';
if not FileExists(slDBPath) then
begin
MessageDlg('Competitions.db does not exist.',mtInformation,[mbOK],0);
exit;
end;
sldb := TSQLiteDatabase.Create(slDBPath);
try
sSQL:= 'DELETE FROM SectionTable WHERE SectionID='+CmbSectSele.Text[1]+';';
sldb.ExecSQL(sSQL);
finally
sldb.Free;
end;
CmbSectSele.ItemIndex:=0;
UpdateCmbSectSele;
RevertSect;
CmbSectSele.Text:='Select Competition';
end;
end;
procedure TDefinitionFrm.CmbAgeRangeChange(Sender: TObject);
begin
Case CmbAgeRange.ItemIndex of
0: begin
EdtLowerAge.Show;
LblAgeRule.Caption:='Over and including';
LblAgeRule.Show;
EdtUpperAge.Hide;
end;
1: begin
EdtLowerAge.Show;
LblAgeRule.Caption:='Under and including';
LblAgeRule.Show;
EdtUpperAge.Hide;
end;
2: begin
EdtLowerAge.Show;
LblAgeRule.Caption:='LblAgeRule';
LblAgeRule.Hide;
EdtUpperAge.Show;
end;
end;
end;
procedure TDefinitionFrm.CmbLevelRangeChange(Sender: TObject);
begin
Case CmbLevelRange.ItemIndex of
0: begin
Edit1.Show;
LblLevelRule.Caption:='Over and including';
LblLevelRule.Show;
EdtUpperLevel.Hide;
end;
1: begin
Edit1.Show;
LblLevelRule.Caption:='Under and including';
LblLevelRule.Show;
EdtUpperLevel.Hide;
end;
2: begin
Edit1.Show;
LblLevelRule.Caption:='LblLevelRule';
LblLevelRule.Hide;
EdtUpperLevel.Show;
end;
end;
end;
procedure TDefinitionFrm.CmbWeightRangeChange(Sender: TObject);
begin
Case CmbWeightRange.ItemIndex of
0: begin
EdtLowerWeight.Show;
LblWeightRule.Caption:='Over and including';
LblWeightRule.Show;
EdtUpperWeight.Hide;
end;
1: begin
EdtLowerWeight.Show;
LblWeightRule.Caption:='Under and including';
LblWeightRule.Show;
EdtUpperWeight.Hide;
end;
2: begin
EdtLowerWeight.Show;
LblWeightRule.Caption:='LblWeightRule';
LblWeightRule.Hide;
EdtUpperWeight.Show;
end;
end;
end;
procedure TDefinitionFrm.CmbHeightRangeChange(Sender: TObject);
begin
Case CmbHeightRange.ItemIndex of
0: begin
EdtLowerHeight.Show;
LblHeightRule.Caption:='Over and including';
LblHeightRule.Show;
EdtUpperHeight.Hide;
end;
1: begin
EdtLowerHeight.Show;
LblHeightRule.Caption:='Under and including';
LblHeightRule.Show;
EdtUpperHeight.Hide;
end;
2: begin
EdtLowerHeight.Show;
LblHeightRule.Caption:='LblHeightRule';
LblHeightRule.Hide;
EdtUpperHeight.Show;
end;
end;
end;
end.