Why does TFDMemTable->SaveToStream() throw an AV - c++builder

I am trying to convert TFDMemTable to a JSON String. I am trying to utilize SaveToStream function, but it throws an NULL Access Violation.
Project XXX raised exception class $C0000005 with message 'access
violation at 0x545c8d4f: read of address 0x00000008'.
A reproducible code below:
TFDMemTable *fd = new TFDMemTable(NULL);
TFieldDef *Field = fd->FieldDefs->AddFieldDef();
Field->Name = "Name";
Field->DataType = Db::ftString;
Field->Size = 100;
fd->Open();
fd->Insert();
fd->FieldByName("Name")->AsString = "Johnny";
fd->Post();
TStringStream *Stream = new TStringStream();
fd->SaveToStream(Stream, sfJSON);
I tried with dropping a TFDStanStorageJSONLink also tried creating TStringStream with a String.
IDE: Rad Studio 11.1. We had a similar working peice of code before upgrading from 10.1 Berlin. Thanks.

The code above is fine, the problem is with the upgraded project file. If I try in a new project, it works. Ended up creating a new project file. My upgrade wows continues.

Related

Getting Delphi to read a database with a new version of Microsoft Access

We use a Delphi 10 programme that reads in an Access database. I do not deeply understand how it does it, except that I believe it uses units called DAO.pas and DAO_TLB.pas.
I recently upgraded from Office 2007 to Office 2016, and since then the Delphi programme is unable to read from the database; it gives the error:
Project MyProj.exe raised exception class EOleSysError with message 'Class not registered'.
I have tried to search to find how to fix this but am struggling because I don't really understand what's going on under the hood. I tried to install the Access 2016 type library, but that didn't seem to make any difference.
Extremely grateful for any help.
Thanks,
Tom
EDIT: DAO.pas is here. DAO_TLB.pas is where the error is triggered; the function which errors is:
class function CoDBEngine.Create: _DBEngine;
begin
Result := CreateComObject(CLASS_DBEngine) as _DBEngine;
end;
Where CLASS_DBEngine is a constant declared as:
CLASS_DBEngine: TGUID = '{CD7791B9-43FD-42C5-AE42-8DD2811F0419}';
I have also just noticed that, when the error occurs, if I click continue rather than break, a new error appears, saying:
Class not registered, ClassID: {CD7791B9-43FD-42C5-AE42-8DD2811F0419}
i.e. the ClassID is the CLASS_DBEngine constant.

F# interactive Marshal.SizeOf with Mono throws “assertion” error

I am trying to read a GIF file header into a structure with F#, using Mono 5.8 on Mac OSX. The following code sample works fine in Visual Studio 2017 on Windows 10; however, when I try to run it in Visual Studio for Mac, I get the following error in F# interactive:
* Assertion at class-accessors.c:138, condition `mono_class_has_static_metadata (klass)' not met
The code I am using is below. The structure is probably incorrect since I just threw it together quickly for the question, but
open System
open System.IO
open System.Runtime.InteropServices
[<Struct; StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)>]
type GifHeader = {
[<MarshalAs(UnmanagedType.ByValTStr, SizeConst = 3)>]
signature: string
[<MarshalAs(UnmanagedType.ByValTStr, SizeConst = 3)>]
version: string
logicalWidth: int16
logicalHeight: int16
}
When I invoke Marshal.SizeOf(typeof<GifHeader>) in Visual Studio for Mac's FSI, I get the error mentioned above.
I noticed that when I am reading into a structure like:
[<Struct; StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)>]
type SomeOtherHeader = {
field1: uint16
field2: int32
field3: int16
field4: float
}
i.e. with no MarshalAs UnmanagedType specification, the error is not thrown.
Does anyone know what this error means? I haven't seen any other instances of this particular error on Google or other SE posts, and it is especially puzzling since it doesn't occur on Windows/.NET Framework 4.7. Not having the interactive window to test code is a massive hindrance for learning, and quite frustrating since I don't think it's possible to use an alternative (non-Mono) FSI.
This was an issue intrinsic to the current Mono release. Per the Mono team, this has been fixed as of Mono 5.14.

CloudTable.Execute not working in API

I just moved a function from an MVC App to an MVC API App, and for some reason it all works except CloudTable.Execute.
Code:
try
{
CloudStorageAccount storageAccount = new CloudStorageAccount(new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(
"accountName",
"key"), true);
CloudTableClient cloudTableClient = storageAccount.CreateCloudTableClient();
CloudTable table = cloudTableClient.GetTableReference("SkypeUsers");
table.CreateIfNotExistsAsync();
TableOperation retrieveOperation = TableOperation.Retrieve<WorkUser>("Skype", skypeid);
TableResult retrievedResult = table.Execute(retrieveOperation); //Does not work
retrievedSkypeId = ((WorkUser)retrievedResult.Result).RowKey;
}
catch (Exception ex)
{
}
Error:
Error CS1061 'CloudTable' does not contain a definition for 'Execute' and no
extension method 'Execute' accepting a first argument of type 'CloudTable' could
be found (are you missing a using directive or an assembly reference?)
The reference to Microsoft.WindowsAzure.Storage is the same version I use in my App. Ive tried cleaning and re-building. Not sure what the issue is.
EDIT:
Print of my only Execute-options:
I am targeting .NET Core & using assembly Microsoft.WindowsAzure.Storage, Version=9.2.0.0.
The ExecuteQuery does not exist within CloudTable for this version.
This might be your case as well.
Use:
table.ExecuteQuerySegmentedAsync(query, null).Result;
The ExecuteQuery sync is still available for .NET Framework version however for NET Standard use ExecuteQuerySegmentedAsync instead.
Error CS1061 'CloudTable' does not contain a definition for 'Execute' and no extension method 'Execute' accepting a first argument of type 'CloudTable' could be found (are you missing a using directive or an assembly reference?)
CloudTable.Execute Method (TableOperation, TableRequestOptions, OperationContext) accepts a TableOperation object as the first argument, and according to the code you provide, we could find you indeed pass a TableOperation object to Execute method, it should not return the error. Please try to install the latest version Microsoft Azure Storage Client Library for .NET to your project (the code works fine with WindowsAzure.Storage v8.0.0 on my side) and test if same issue will appear. You could also tell us the version of WindowsAzure.Storage you are using now, and then we will test the code with that version.
Besides, please try to use TableQuery to generate a query and call CloudTable.ExecuteQuery method to retrieve the entity.
TableQuery<WorkUser> query = new TableQuery<WorkUser>().Where(
TableQuery.CombineFilters(
TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "Skype"),
TableOperators.And,
TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, skypeid)));
retrievedSkypeId = table.ExecuteQuery(query).FirstOrDefault().RowKey;

Troubleshoot the SqlProgrammabilityProvider

I can't seem to get the SqlProgrammabilityProvider to work even in the most basic configuration. With this code
type TestDb = SqlProgrammabilityProvider<testConn>
let db = TestDb()
I get the design/compile-time error "The value or constructor 'TestDb' is not defined"
testConn is a literal string that is working fine with the SqlCommandProvider in the same project.
I'm using VS 2015, FSharp.Data.SqlClient 1.7.5, and I've tried targeting .NET 4.5.2 and 4.6.
Are there known issues or limitations with this? If not, how could I troubleshoot it?
After getting a type for SqlProgrammabilityProvider upon a specific connection you should tie it to as many as you like, but of the concrete following options: Sql Server function, stored procedure, or table.
Like in:
type TestDb = SqlProgrammabilityProvider<testConn>
type Datatable = TestDb.dbo.Tables.MyDataTable
or
use cmd = TestDB.dbo.MyStoredProcedure()
cmd.Execute(Param1="xyzzy")
You may peek at use cases at https://github.com/fsprojects/FSharp.Data.SqlClient/tree/master/src/SqlClient.Tests

Class Type Expected error on TableAdapter constructor

I am using Delphi Prism to connect to an Advantage Database Server. I created a connection using the server explorer to the database. I added a dataset object to my project and added a table to the dataset. Everything works fine in the IDE, however, I get an error in the generated designer code on the table adapter constructor.
The error is: (PE26) Class type expected.
Here is the generated code:
{ Presidents.PresidentsTableAdapters.USPRESIDENTSTableAdapter }
constructor Presidents.PresidentsTableAdapters.USPRESIDENTSTableAdapter;
begin
self.ClearBeforeFill := true;
end;
does it help to leave out the "self."? i would expect "self." is unnecessary. i use it only rarely.
Can you show the full file? The error says that "Presidents.PresidentsTableAdapters.USPRESIDENTSTableAdapter" is not a known class type.

Resources