Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 968361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:28:00+00:00 2026-05-16T02:28:00+00:00

In Delphi I have a structure like this: TCustomerInfo = Packed Record CustomerNo: Integer;

  • 0

In Delphi I have a structure like this:

  TCustomerInfo = Packed Record
    CustomerNo: Integer;
    FirstName: String[50];
    LastName: String[50];
  End;

With a dummy-proc like this:

procedure GetCustomer(CustomerNo: Integer; var CustomerInfo: TCustomerInfo);
begin
  CustomerInfo.CustomerNo := 19901;
  CustomerInfo.FirstName := 'JOHN';
  CustomerInfo.LastName := 'DOE';
end;

In C# I have this:

 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi, Pack=1)]
 struct CUSTOMER_INFO
 {
  public Int32 CustomerNo;
  [MarshalAs(UnmanagedType.ByValTStr, SizeConst=50)]
  public string FirstName;
  [MarshalAs(UnmanagedType.ByValTStr, SizeConst=50)]
  public string LastName;
 }

With an imported Delphi function like this:

 [DllImport("Exceline.dll")]
 extern static void GetCustomer(Int32 CustomerNo, ref CUSTOMER_INFO CustomerInfo);

The idea is to make sure all memory allocation and storage is being handled by the C# application.

My problem is that nothing gets assigned to my C# struct upon return from GetCustomer :-/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T02:28:01+00:00Added an answer on May 16, 2026 at 2:28 am

    I finally came up with a solution which avoids all the Alloc/FreeHGlobal, but if this is truly bulletproff with regards to the garbage collector is another matter.

    The solution is to first clear the TCustomer structure with FillChar then copy the data using the Move procedure.

    The delphi record looks like this:

      TCustomer = packed record
        CustomerNo: Integer;
        FirstName: array [1..50] of Char;
        LastName: array [1..50] of Char;
      end;
    

    Then i copy the string to the structure with a procedure:

    procedure StrToBuf(Str: String; var buf);
    begin
      Move(Pointer(str)^, buf, Length(str));
    end;
    

    Within a proc more or less like this:

    procedure LoadCustomerFromQuery(var Query: TQuery; var Customer: TCustomer); stdcall;
    begin
    
      FillChar(Customer, SizeOf(Customer), 0);
    
      StrToBuf(Query.FieldByName('FNAVN').AsString, Customer.FirstName);
      StrToBuf(Query.FieldByName('ENAVN').AsString, Customer.LastName);
    
      Customer.CustomerNo := Query.FieldByName('KUNDENR').AsInteger;
    
    end;
    

    Finally the C# struct looks something like this:

    [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi, Pack=1)]
    public struct TCustomer
    {
        public Int32 CustomerNo;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 50)]
        public string FirstName;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 50)]
        public string LastName;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 486k
  • Answers 486k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer That's a mistake in the example-code. It assumes that the… May 16, 2026 at 8:08 am
  • Editorial Team
    Editorial Team added an answer See this question, I believe it contains both an answer… May 16, 2026 at 8:08 am
  • Editorial Team
    Editorial Team added an answer This should work on 1.6 or later (if I recall… May 16, 2026 at 8:08 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.