Nijesh
Nijesh

Reputation: 55

How to translate the string which is declared in Array in delphi?

We have the application in delphi and now we are implementing language translation feature. We added the code in core to translate the strings which are declared in ResourceString. It is working fine but strings which is declared in Array not translated. Example

resourcestring
 Error_Text = 'Invalid Value'; 

This is Working fine.

Const
 ERROR_TYPE : Array[0..2] of String = ('Invalid Name', 'Invalid Age', 'Invalid Address');

How do i add these array values into resourcestring?

Upvotes: 4

Views: 310

Answers (1)

Uli Gerhardt
Uli Gerhardt

Reputation: 14001

I think you can't directly have an array of resourcestring. I'd try a function instead, something like:

resourcestring
  ERROR_TYPE0 = 'Invalid Name';
  ERROR_TYPE1 = 'Invalid Age';
  ERROR_TYPE2 = 'Invalid Address';

type
  TMyIndexType = 0..2;

function ERROR_TYPE(AIndex: TMyIndexType): string;
begin
  case AIndex of
    0: Result := ERROR_TYPE0;
    1: Result := ERROR_TYPE1;
    2: Result := ERROR_TYPE2;
    else
      // appropriate error handling
  end;
end;

Upvotes: 6

Related Questions