I use an ADOQuery, ADODataSource and DBGrid to populate a Read-only DBGrid from an Access table. I then use an ADOCommand to execute an SQL statement to either Update, Insert or Delete a record in the table. How do I get the DBGrid to automatically display the updated table? I have tried to Refresh or Update the DBGrid, also Close and Open, and Active=False and True on the ADOQuery, all to no avail.
I tried to define a TDataSource which I can Create before running the query and FreeAndNil afterwards but, I get an error 'Not enough parameters' when I do MyDataSource := TDataSource.Create. I think this approach could work?
All I have is an ADOQuery, an ADODataSource and a DBGrid. I tried to create the ADOQuery and DataSource programmatically but it did not work. I have not tried to do the same with the DBGrid. To my knowledge a DataSource does not have an Active, Close, Open or Refresh property, that's why I tried creating and freeing it but the data still did not change in the DBGrid.
Str := 'UPDATE tblTransaction SET tblTransaction.Category = "' + NewCat+ '", ' +
'tblTransaction.TaxDeductable="' + NewExp + '" ' +
'WHERE (((tblTransaction.Category) = "ZZZZ"));';
cmdCategory.CommandText := Str;
//and then this bit in the ShowData procedure
with qryCategory do
Active := False; //I also tried Close and Open
ConnectionString := cnnStr;
SQL.Text := 'SELECT Category,Expense FROM tblCategory ORDER BY Category';
Active := True;
//The DBGrid should now show this change
You should use only one connection.
If you set a connection string on a ADOQuery or ADOCommand then the VCL will generate a new hidden connection in the background for the component.
Each connection has it's own cache inside of the driver (jet engine) for the access database.
If you modify the database through one connection the other connection will not see this change immediatly.
It needs about 6 to 10s to write the changes to the *.mdb file.
After that the other connection has the opportunity to read the changes.
==> allways use only one connection (TADOConnection)
Want to send a jpeg as an attachment without using file folder to save the attachment temporarily.
Is it possible to insert the jpeg file from application inside the message body as OLE? If yes, how to do this?
I'm writing an opc client in delphi and I'm having some problems with the ondatachange event. It is giving me an event failed with error code 0x80010105. It would appear that when i'm busy with handling an event i'm getting the next and then i'll get an error.
My question is does anybody know how I can possibly solve this?
Thank you for the answer, but it was actually an error in my client program that handled a datachange event wrong. so that the received arrays went out of bounds or the values that I got back were handled worng.
I have an application that is sending commands that are being added to a queue to a connected device. There are times when I need to send a command right away, so I need a way to add an object to the front of the queue so that the command gets sent right away instead of having it added to the end of the queue. Does anyone know how to do this? I am using a TQueue object.
I have some code which leaks memory (it's pretty much copied straight from Rudy's Delphi Corner). I have found the line that which causes the problem, but I don't understand why it's leaking which makes me concerned. I am reluctant to just fix it without knowing what's actually wrong.
The purpose of the code is to create a separate copy of a TVarRec variable. Here goes:
function TfrmMain.CopyVarRec(const Item: TVarRec): TVarRec;
// Copy entire TVarRec first.
Result := Item;
// Now handle special cases.
case Item.VType of
Result.VExtended^ := Item.VExtended^;
Result.VPChar := StrNew(Item.VPChar);
// A little trickier: casting to string will ensure
// reference counting is done properly.
// Nil out first, so no attempt to decrement
// reference count.
Result.VAnsiString := nil;
string(Result.VAnsiString) := string(Item.VAnsiString);
The following function is then used to free the copied TVarRec:
// TVarRecs created by CopyVarRec must be finalized with this function.
// You should not use it on other TVarRecs.
procedure TfrmMain.FinalizeVarRec(var Item: TVarRec);
case Item.VType of
// vtAnsiString uses reference counting.
Item.VInteger := 0;
The above code leaks memory when the TVarRec contains an AnsiString, that is in the vtAnsiString case of the CopyVarRec function. The weird thing is, the memory leak goes away if I remove the line
Result.VAnsiString := nil;
before assigning the Item's string to teh string of the the Result. If I remove it, the memory leak goes away and (it appears) the program works fine, but I really don't feel comfortable doing so without understanding why that line causes the problem to begin with.
The line which nils the Result's pointer to the string is needed, because otherwise the code which copies the string will cause the strings reference counter to decrease to 0, freeing the string. This is why the application "stopped" leaking memory when the nil-ing row was removed.
Instead, FinalizeVarRec needed to actually set the AnsiString to the empty string too, to make sure the string was freed. I believed taht would be handled by the reference counting, but it doesn't work that way for pointers.
I'm considering going back to school, in order to learn to program. The potential teacher wants to see a quick demonstration of the software that I have written in the past. Unfortunately, those require Interbase 6.
Does anyone have an installation-package for me?
Many thanks in advance!
I are troll
Last Visit: 11-Nov-19 18:02 Last Update: 11-Nov-19 18:02