I tryed to use this to change the title of a window when a button is
pressed, but it doesn't work.
I am using this string:
const
MyUTF8String = 'Texto ł ñ ø ß á';
Encoded with UTF-8. I opened the file with TextWrangler to ensure it's
really utf-8
And tryed to set the window title with this code:
function ButtonMessagePressed: OSStatus;
var
CFString: CFStringRef;
begin
CFString := CFStringCreateWithCString(nil,
Pointer(PChar(MyUTF8String)), kCFStringEncodingUTF8);
SetWindowTitleWithCFString(MainWindow, CFString);
CFRelease(CFString);
result := 0;
end;
But it doesn't work. I only see 'Texto' and not my entire string. i.e.
the special characters disappeared.
Here is a full compilable test program (there are some other things on
it, but they shouldn't interfere):
{
carbontest.pas
*****************************************************************************
* *
* This demonstration program is public domain, which means no copyright, *
* but also no warranty! *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
*****************************************************************************
}
program carbontest;
{ Functions to easely generate carbon structures }
function GetQDRect(Left, Top, Width, Height: Integer): FPCMacOSAll.Rect;
begin
result.Left := Left;
result.Top := Top;
result.Right := Left + Width;
result.Bottom := Top + Height;
end;
{ Shows a message box }
procedure DoShowMessage(ATitle, AMsg: string);
var
outItemHit: SInt16;
err: OSErr;
begin
err := StandardAlert(kAlertNoteAlert, ATitle, AMsg, nil, outItemHit);
end;
{ Event handling routines }
function ButtonHelloPressed: OSStatus;
begin
result := 0;
end;
function ButtonMessagePressed: OSStatus;
var
CFString: CFStringRef;
begin
CFString := CFStringCreateWithCString(nil,
Pointer(PChar(MyUTF8String)), kCFStringEncodingUTF8);
SetWindowTitleWithCFString(MainWindow, CFString);
CFRelease(CFString);
result := 0;
end;
{ Message handling function }
function WindowCommandHandler(nextHandler: EventHandlerCallRef;
theEvent: EventRef; userDataPtr: UnivPtr): OSStatus;
var
status: OSStatus;
ignoreresult: OSStatus;
aCommand: HICommand;
begin
status := eventNotHandledErr;
if aCommand.commandID = FOUR_CHAR_CODE(kButtonHello) then status :=
ButtonHelloPressed()
else if aCommand.commandID = FOUR_CHAR_CODE(kButtonMessage) then
status := ButtonMessagePressed();
result := status;
end;
{ Initialization and finalization routines }
procedure Initialize;
var
status, ignoreResult: OSStatus;
cmdEvent: EventTypeSpec;
eventHandler: EventHandlerUPP;
fontStyle: ControlFontStyleRec;
begin
status := CreateNewWindow(kDocumentWindowClass,
(kWindowStandardDocumentAttributes or kWindowStandardHandlerAttribute
or kWindowCompositingAttribute),
GetQDRect(100, 100, 350, 350), mainWindow);
if (status <> noErr) or (mainWindow = nil) then
begin
DoShowMessage('Error', 'CreateNewWindow failed');
Exit;
end;
{ Closes all windows, so they have time to save any user data (none in
this case) }
procedure Finalize;
begin
DoCloseWindow(mainWindow);
end;
{ Main program section }
begin
Initialize();
RunApplicationEventLoop();
Finalize();
end.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden
This email sent to email@hidden