How to update a column value?
Posted: Thu 27 Aug 2015 14:33
I have just started working with VirtualTable, as it looks very promising.
I defined a table with a fleet ID (string) and some fields I want to keep some counts in (integer).
When I find a condition in the data that requires a tally, I use this delphi code:
... UpdateMWO(Grid.cell[7,i]);
with this routine:
procedure TForm1.UpdateMWO(MyIndex : string);
begin
EMPTable.Locate('vtFleet',MyIndex,[]);
EmpTable.FieldByName('vtMWO').AsInteger := EmpTable.FieldByName('vtMWO').AsInteger + 1;
EMPTable.Post;
end;
but there are no updates to the value of the column. When I later move the virtual table to a grid for display:
EMPTable.First;
for i := 1 to 7 do // there are only 7 fleets
begin
AGWB.Grid.Cells[0,i] := EMPTable.FieldByName('vtFleet').AsString;
AGWB.Grid.Cells[1,i] := EMPTable.FieldByName('vtBSEmp').AsString;
AGWB.Grid.Cells[2,i] := EMPTable.FieldByName('vtBSWOEmp').AsString;
AGWB.Grid.Cells[3,i] := EMPTable.FieldByName('vtBSWO').AsString;
AGWB.Grid.Cells[5,i] := EMPTable.FieldByName('vtMEmp').AsString;
AGWB.Grid.Cells[6,i] := EMPTable.FieldByName('vtMWOEmp').AsString;
AGWB.Grid.Cells[7,i] := EMPTable.FieldByName('vtMWO').AsString;
if EMPTable.FieldByName('vtBSWOEmp').AsInteger <> 0 then
AGWB.Grid.Cells[4,i] := FormatFloat('#####0.000',EMPTable.FieldByName('vtBSWO').AsInteger / EMPTable.FieldByName('vtBSWOEmp').AsInteger)
else
AGWB.Grid.Cells[4,i] := '0';
if EMPTable.FieldByName('vtMWOEmp').AsInteger <> 0 then
AGWB.Grid.Cells[8,i] := FormatFloat('#####0.000',EMPTable.FieldByName('vtMWO').AsInteger / EMPTable.FieldByName('vtMWOEmp').AsInteger)
else
AGWB.Grid.Cells[8,i] := '0';
EMPTable.Next;
end;
All the resulting values are the ones that were set when creating the data originally, as with this row:
EmpTable.Append;
EmpTable.FieldByName('vtFleet').AsString := '15';
EmpTable.FieldByName('vtBSEmp').AsInteger := CountTotal('15','BODY');
EmpTable.FieldByName('vtBSWOEmp').AsInteger := 0;
EmpTable.FieldByName('vtBSWO').AsInteger := 0;
EmpTable.FieldByName('vtMEmp').AsInteger := CountTotal('15','MAINT');
EmpTable.FieldByName('vtMWOEmp').AsInteger := 0;
EmpTable.FieldByName('vtMWO').AsInteger := 0;
EmpTable.Post;
CountTotal is a routine that returns an integer value from a SQL count(*) query.
How should a field be updated? I am at a loss at this time.
Thanks for any help.
I defined a table with a fleet ID (string) and some fields I want to keep some counts in (integer).
When I find a condition in the data that requires a tally, I use this delphi code:
... UpdateMWO(Grid.cell[7,i]);
with this routine:
procedure TForm1.UpdateMWO(MyIndex : string);
begin
EMPTable.Locate('vtFleet',MyIndex,[]);
EmpTable.FieldByName('vtMWO').AsInteger := EmpTable.FieldByName('vtMWO').AsInteger + 1;
EMPTable.Post;
end;
but there are no updates to the value of the column. When I later move the virtual table to a grid for display:
EMPTable.First;
for i := 1 to 7 do // there are only 7 fleets
begin
AGWB.Grid.Cells[0,i] := EMPTable.FieldByName('vtFleet').AsString;
AGWB.Grid.Cells[1,i] := EMPTable.FieldByName('vtBSEmp').AsString;
AGWB.Grid.Cells[2,i] := EMPTable.FieldByName('vtBSWOEmp').AsString;
AGWB.Grid.Cells[3,i] := EMPTable.FieldByName('vtBSWO').AsString;
AGWB.Grid.Cells[5,i] := EMPTable.FieldByName('vtMEmp').AsString;
AGWB.Grid.Cells[6,i] := EMPTable.FieldByName('vtMWOEmp').AsString;
AGWB.Grid.Cells[7,i] := EMPTable.FieldByName('vtMWO').AsString;
if EMPTable.FieldByName('vtBSWOEmp').AsInteger <> 0 then
AGWB.Grid.Cells[4,i] := FormatFloat('#####0.000',EMPTable.FieldByName('vtBSWO').AsInteger / EMPTable.FieldByName('vtBSWOEmp').AsInteger)
else
AGWB.Grid.Cells[4,i] := '0';
if EMPTable.FieldByName('vtMWOEmp').AsInteger <> 0 then
AGWB.Grid.Cells[8,i] := FormatFloat('#####0.000',EMPTable.FieldByName('vtMWO').AsInteger / EMPTable.FieldByName('vtMWOEmp').AsInteger)
else
AGWB.Grid.Cells[8,i] := '0';
EMPTable.Next;
end;
All the resulting values are the ones that were set when creating the data originally, as with this row:
EmpTable.Append;
EmpTable.FieldByName('vtFleet').AsString := '15';
EmpTable.FieldByName('vtBSEmp').AsInteger := CountTotal('15','BODY');
EmpTable.FieldByName('vtBSWOEmp').AsInteger := 0;
EmpTable.FieldByName('vtBSWO').AsInteger := 0;
EmpTable.FieldByName('vtMEmp').AsInteger := CountTotal('15','MAINT');
EmpTable.FieldByName('vtMWOEmp').AsInteger := 0;
EmpTable.FieldByName('vtMWO').AsInteger := 0;
EmpTable.Post;
CountTotal is a routine that returns an integer value from a SQL count(*) query.
How should a field be updated? I am at a loss at this time.
Thanks for any help.