Using an Interbase database I have an application in which I want to show the contents of an memo field.
I have created a datamodule on which I put a TIBDatabase, TIBTransaction, TDataSource and TIBTable all connected. Data comes out, no problems so far.
But when I add a TDBMemo to a form and want to show the contents all I get is this;
I have only set the DataSource and DataField on the TDBMemo so there is no further code involved.
Any thoughts?
Solved it by replacing the TDBMemo with an TMemo and adding the contents to it with;
Encoding.Unicode.GetString(myQuery.FieldByName('myField').AsBytes);
Related
I am creating a memory table TFDMemTable for a delphi form, and define the fields under FieldDefs. After I am done with the definition of the fields manually, I go to the Fields Editor to add the fields that I just defined.
Everything works perfect until I have an AutoInc type field in my FDMemTable. I am using Delphi 10.3.2 version and I was wondering if I am missing anything or this is a IDE bug.
PS: I have done couple of tests, and I think that if the AutoInc field is not defined as the last field, everything disappears. I am not %100 sure of this case, but pretty much every time I try I loose the fields under FieldDefs.
Here is the steps:
Place a FDMemTable icon
Open FieldDefs window
Create a bunch of fields (string, integer ...)
define the names, types (and sizes for strings)
Open FieldsEditor
Add fields
until here everything works as they should.
Go back to fieldDefs window
create and name a new field with autoinc type
open the fields editor screen and add the last added field.
everything is still good to go as long as there is no more changes in the structure.
Here the weird thing happens if you do the following.
open FieldDefs window
create any field ( lets say integer type )
Go to Fields Editor window to add this last created field.
and you will see that you don't see this new field to add.
when you go back to fieldDefs window to see why it is not showing,
you will see all the previous and last added fields' definitions gone..
In order for me to go around this problem, I open the form in text form and insert the new field right before the last field which is autoinc,
add field editor entry manually in the text form,
and when everything is right, I toggle to form view.
The context is that I am maintaining an application running on delphi 7 with the BDE. I programmatically assign dbricheditcontrols' datafields to allow users to edit rtf documents. When the relevant forms open, the unformatted text is displayed and then once say the person moves onto the next document, suddenly the rich text kicks in; I suspect it must be an initialisation problem of sorts, but what am I missing; could not locate a solution online.
Thanks
Ordinarily, I would not post an answer to a q which states
I programmatically assign dbricheditcontrols' datafields to allow users to edit rtf documents
but fails to include the code that you are using - you should have provided an MCVE (see https://stackoverflow.com/help/mcve).
However, what you say sugggests that you may be going about what you are trying to do the wrong way. You say you are using a TDBRichEdit component, but if you are using it correctly, it should not require any programmatic assignment of datafields to do it: you simply need to connect the component to the TTable or TQuery you are using via a TDataSource component, and configure the DBRichEdit to access whatever field of the TTable/TQuery that stores the richedit text. That can be done a design time using the Object Inspector in the IDE to set properties and does not require any code.
So, it seems to me that either you are not using the DBRichEdit correctly, or you are trying to do something that you have not explained in your q.
You can satisfy yourself that a DBRichEdit works automatically, without needing to load or save its contents in code, as follows:
Open the FishFacts demo
Add a TDBNavigator and a TDBRichEdit to the form. Set the DataField property of DBRichEdit1 to Notes.
Set the ReadOnly property of Table1 to False. Then set Table1's Active property to True.
Compile and run the project. While it's running
Start WordPad.Exe and create a bit of richtext in it. Copy it to the clipboard. Click the Save speedbutton of DBNavigator1.
Paste the richtext into DBRichEdit1.
You should find that you can navigate away from and back to the edited record and the richtext will be automatically reloaded.
Also, the following code works fine for me to load the Notes field from an .Rtf file
procedure TForm1.Button1Click(Sender: TObject);
begin
Table1.Edit;
TMemoField(Table1.FieldByName('Notes')).LoadFromFile('D:\test.rtf');
end;
and does not initially display the unformatted text as you describe. So I'm fairly sure you problem is arising in code of yours that you haven't shown us.
Btw, the only reason I am posting this as an "answer" is that there is more to say than will comfortably fit in a comment.
Since I don't want to use ODBC connections anymore, I'm trying to get DBX work for my reports. Almost everything works the same as it worked with the tfrxAdoQuery, but not the GroupFooter.
I used to have a MasterData that used a ADOQuery1: TfrxAdoQuery and I changed to a DBXQuery1:TfrxDBXQuery. Its fields like [BDXQuery."name"] work fine now than I'm using a different type of query, but only inside the MasterData. This is the way it looks in the MasterData and when the report is displayed it comes correctly:
For some reason, the Footer's tfrxMemoViews dont show the DBXQuery1."anyField" that I try to display.
This is the way it looks in the footer but in the report just dont show the name.
The difference is the DatasetName can't be set for the DBXQuery (as it was set when using the ADOquery). When I was using ADO, the DatabaseName seem to be assinged arbitrarilly with a name like 'header' which did not belong to any component or variable. Now it should be more manageable since the fields that are set are DataSet (wich can be chosen from a group that has all the DataSets, in my case I can choose DBXQuery1) and DataField, which can be chosen from one of the predetermined fields that are in the DBXQuery1.
Any help will be highly appreciated
I have a DLL created in Delphi XE2 that is using DB Express and TClientDataSet to display the results of a join in a DB Grid. There is a simple function to launch/show the form that is exported for use in other applications. The query is executed, and the grid populated, on FormActivate.
When I call the function to show the form from a separate Delphi XE2 application, everything runs fine - no issues that I can find.
However, when I call the same function from a separate Delphi 7 application, I get an error that that TClientDataSet can't find fields from the join.
For Example, data is returned like this:
[dbxds == TSQLDataSet
cds == TClientDataSet]
dbxds.commandtext='select s.sfield1, s.sfield2, t.tfield1, t.tfield2 from s left join t on s.sfield1 = t.tfield1';
cds.Open;
cds.fieldByName(sfield2).visible:=false;//to hide from a dbgrid
cds.fieldByName(tfield2).visible:=false;//to hide from a dbgrid
When called from XE2, no issues.
When called from Delphi 7, the last line (used to hide that field from the db grid) gives an error that:
cds: Field 'tfield2' not found
Though the first line is fine - if I switch the order of the query so that that 't' fields are retrieved first ('from t left join s'), then I get the error on the 's' field instead.
Any thoughts on what could be causing the incompatibility?
Thanks!
OK so, I noticed something odd and that put me on the path to getting the answer to this.
It just happened that, in either table, the field I was trying to access to hide was of type 'tinyint(1)'. If I tried to hide a field of type int/varchar etc, no error was thrown.
I swapped my 'tinyint(1)' fields for 'int(1)' and it works fine.
No idea why this was happening, but I'm glad I caught it and, if any one else runs into this issue, I hope that this answers their question for them too.
I have a database table in which I need to insert records.
I'm using a updatable TClientDataset and everything works just fine.
Now, I need to add a dummy field; not a calculated one.
One field where I can write the row state (just some information I will use before ApplyUpdates) but that is not part of the database table.
I've seen this illuminating post, but the added field is calculated and it is not possible to update and keep informations.
It is not ok for me.
I've tried to add a 'dummy field' from the database select and fix the ProviderFlags to remove the pfUpdate.
cds.CommandText := 'SELECT 1 AS DUMMY , CUSTOMERS.* FROM CUSTOMERS';
cds.Open;
cds.FieldByName('DUMMY').ProviderFlags := [];
I've seen in the Provider.pas that before building the insert sql, the ProviderFlags is checked. This should work indeed, the problem is it seems that ProviderFlags is not updated from my statement above.
Please, do you know how to add a Field on the fly, that is writable but then ignored by the delphi database update process?
I'm using delphi 7.
Thanks for you help.
Make the field an InternalCalc field and set its ProviderFlags to []. This makes the field writable to your application, but skips the field when updating the underlying database.