MrError
asked on
Loading controls from an object and having trouble.
Hello experts,
I have a problem getting the data from an object to load into my controls. I will show you the two chunks of code that I am using to do this. The first part is the Load object routine that is done at right at execute time. This is also used any time a on click is used on one control.
procedure TGymMgr.LoadAerobicObj;
var
oAerobic : TAerobic;
x : integer;
begin
if Aerobic.Count > 0 then
for x := Aerobic.Count -1 downto 0 do
Aerobic.Delete(x);
qryGym.Close;
qryGym.SQL.Clear;
qryGym.SQL.Add ( 'Select EMP, TDATE, ENTRY, ATYPE, ' );
qryGym.SQL.Add ( 'MEDEXEMPT, TTIME, HEARTRATE, VO2MAX, BIKELOAD, ' );
qryGym.SQL.Add ( 'SEATPOS, RATING, RMODIFY ' );
qryGym.SQL.Add ( 'from GYM.AEROBIC ' );
qryGym.Sql.Add ( WhereIs );
qryGym.SQL.SaveToFile('H:\ Gym.sql');
qryGym.Open;
qryGym.first;
while not qryGym.eof do begin
oAerobic := TAerobic.Create;
oAerobic.Emp := qryGym.FieldByName('EMP'). AsString;
oAerobic.Tdate := qryGym.FieldByName('TDATE' ).AsString ;
oAerobic.Entry := qryGym.FieldByName('ENTRY' ).AsString ;
oAerobic.Atype := qryGym.FieldByName('ATYPE' ).AsString ;
oAerobic.Medexempt := qryGym.FieldByName('MEDEXE MPT').AsSt ring;
oAerobic.Ttime := qryGym.FieldByName('TTIME' ).AsString ;
oAerobic.Heartrate := qryGym.FieldByName('HEARTR ATE').AsSt ring;
oAerobic.Vo2max := qryGym.FieldByName('VO2MAX ').AsStrin g;
oAerobic.Bikeload := qryGym.FieldByName('BIKELO AD').AsStr ing;
oAerobic.Seatpos := qryGym.FieldByName('SEATPO S').AsStri ng;
oAerobic.Rating := qryGym.FieldByName('RATING ').AsStrin g;
oAerobic.Rmodify := qryGym.FieldByName('RMODIF Y').AsStri ng;
oAerobic.ObjStatus := OK;
oAerobic.ObjState := ExistingObject;
Aerobic.Add ( oAerobic );
qryGym.Next;
end;
qryGym.Close;
end;
// this procedure in located within my main form. It sends the WhereIs statement to
the above procedure and then loads the data into the controls on the form.
procedure TfrmTest.LoadAerobic;
Var
i : integer;
begin
employeeNo := '325'; // these are not in my program actually I put them there
testDay:= '12/04/1999'; // just so you can see what the data looks like
Screen.Cursor := crHourGlass;
GymMgr.whereIs := 'Where Emp = ''' + EmployeeNo + ''' '
+ 'And TDate = to_date(''' + TestDay + ''', ''MM/DD/YYYY'' ) ';
gymmgr.LoadAerobicObj; // this is where my first procedure gets called
GymMgr.whereIs := '';
//--- Aerobic testing Info
edtAMed.Text := oAero.medexempt; //access violation at address ect...
edtType.text := oAero.atype;
edtATime.text := oAero.ttime;
edtHeart.text := oAero.heartrate;
edtSeatPos.text := oAero.seatpos;
edtBike.text := oAero.Bikeload;
edtVo2Max.text := oAero.vo2max;
edtARate.text := oAero.rating;
Screen.Cursor := crArrow;
end;
When I make break points and follow through... It will give me an access violation error. I think it maybe somthing to do with my list not being created but when I do an evaluate of GmyMgr.Aerobic.count I get 1 row, which is what I expect to have.
Well any ideas are weclome,
David
I have a problem getting the data from an object to load into my controls. I will show you the two chunks of code that I am using to do this. The first part is the Load object routine that is done at right at execute time. This is also used any time a on click is used on one control.
procedure TGymMgr.LoadAerobicObj;
var
oAerobic : TAerobic;
x : integer;
begin
if Aerobic.Count > 0 then
for x := Aerobic.Count -1 downto 0 do
Aerobic.Delete(x);
qryGym.Close;
qryGym.SQL.Clear;
qryGym.SQL.Add ( 'Select EMP, TDATE, ENTRY, ATYPE, ' );
qryGym.SQL.Add ( 'MEDEXEMPT, TTIME, HEARTRATE, VO2MAX, BIKELOAD, ' );
qryGym.SQL.Add ( 'SEATPOS, RATING, RMODIFY ' );
qryGym.SQL.Add ( 'from GYM.AEROBIC ' );
qryGym.Sql.Add ( WhereIs );
qryGym.SQL.SaveToFile('H:\
qryGym.Open;
qryGym.first;
while not qryGym.eof do begin
oAerobic := TAerobic.Create;
oAerobic.Emp := qryGym.FieldByName('EMP').
oAerobic.Tdate := qryGym.FieldByName('TDATE'
oAerobic.Entry := qryGym.FieldByName('ENTRY'
oAerobic.Atype := qryGym.FieldByName('ATYPE'
oAerobic.Medexempt := qryGym.FieldByName('MEDEXE
oAerobic.Ttime := qryGym.FieldByName('TTIME'
oAerobic.Heartrate := qryGym.FieldByName('HEARTR
oAerobic.Vo2max := qryGym.FieldByName('VO2MAX
oAerobic.Bikeload := qryGym.FieldByName('BIKELO
oAerobic.Seatpos := qryGym.FieldByName('SEATPO
oAerobic.Rating := qryGym.FieldByName('RATING
oAerobic.Rmodify := qryGym.FieldByName('RMODIF
oAerobic.ObjStatus := OK;
oAerobic.ObjState := ExistingObject;
Aerobic.Add ( oAerobic );
qryGym.Next;
end;
qryGym.Close;
end;
// this procedure in located within my main form. It sends the WhereIs statement to
the above procedure and then loads the data into the controls on the form.
procedure TfrmTest.LoadAerobic;
Var
i : integer;
begin
employeeNo := '325'; // these are not in my program actually I put them there
testDay:= '12/04/1999'; // just so you can see what the data looks like
Screen.Cursor := crHourGlass;
GymMgr.whereIs := 'Where Emp = ''' + EmployeeNo + ''' '
+ 'And TDate = to_date(''' + TestDay + ''', ''MM/DD/YYYY'' ) ';
gymmgr.LoadAerobicObj; // this is where my first procedure gets called
GymMgr.whereIs := '';
//--- Aerobic testing Info
edtAMed.Text := oAero.medexempt; //access violation at address ect...
edtType.text := oAero.atype;
edtATime.text := oAero.ttime;
edtHeart.text := oAero.heartrate;
edtSeatPos.text := oAero.seatpos;
edtBike.text := oAero.Bikeload;
edtVo2Max.text := oAero.vo2max;
edtARate.text := oAero.rating;
Screen.Cursor := crArrow;
end;
When I make break points and follow through... It will give me an access violation error. I think it maybe somthing to do with my list not being created but when I do an evaluate of GmyMgr.Aerobic.count I get 1 row, which is what I expect to have.
Well any ideas are weclome,
David
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
You may also have a memory leak ->
if Aerobic.Count > 0 then
for x := Aerobic.Count -1 downto 0 do
Aerobic.Delete(x);
I think should read:
if Aerobic.Count > 0 then
for x := Aerobic.Count -1 downto 0 do begin
TAerobic(Aerobic.Items[x]) .Free; // <- free the aerobic object BEFORE deleting the pointer to it
Aerobic.Delete(x);
end;
PS. The Aerobic.Count>0 is superfluous as the for x line would get executed if count was 0 as it would eval to -1 downto 0
if Aerobic.Count > 0 then
for x := Aerobic.Count -1 downto 0 do
Aerobic.Delete(x);
I think should read:
if Aerobic.Count > 0 then
for x := Aerobic.Count -1 downto 0 do begin
TAerobic(Aerobic.Items[x])
Aerobic.Delete(x);
end;
PS. The Aerobic.Count>0 is superfluous as the for x line would get executed if count was 0 as it would eval to -1 downto 0
ASKER
aubs & djadja
Well you both were right. Thank you for your excellent ideas.
Since aubs answered my main question I will give her the points but djadja I did have a memory leak so thank for resolving that.
David
Well you both were right. Thank you for your excellent ideas.
Since aubs answered my main question I will give her the points but djadja I did have a memory leak so thank for resolving that.
David
Thats quite alright.
Glad to be of service :)
Glad to be of service :)
ASKER
Huh that just may do it. Let me try a few more things with this and I will let you know if that was all I forgot.
Thank you,
David