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

  • SEARCH
  • Home
  • 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 7006539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:29:26+00:00 2026-05-27T21:29:26+00:00

This question refers to this one along with its accepted answer posted here on

  • 0

This question refers to this one along with its accepted answer posted here on stackoverflow.

I don’t feel comfortable at Windows API programming.

Exploring the way EasyGPS by Topografix handles clipboard manipulations, I discovered that it uses a custom clipboard format named GPX wich is actually plain XML text (GPX to be precise). Using Clipboard.AsText is excluded.

I stumble at this stage:

program ProbeClipboard;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Windows,
  ClipBrd;

var
  CF_GPX: Cardinal;
  ClipboardData: THandle;

begin
  CF_GPX:=RegisterClipboardFormat('GPX');

  if ClipBoard.HasFormat(CF_GPX) then
  begin
    Writeln('GPX format available in clipboard');
    //
    OpenClipboard(0);

    ClipboardData := GetClipboardData(CF_GPX);

    if ClipboardData = 0 then
      raise Exception.Create('Clipboard data Error');

    /// How to use GlobalLock and GlobalUnLock
    /// so that I can paste the Clipboard data
    /// to a TMemo instance for example

    CloseClipboard;
  end;
end.

Please, help me to fix that program.

  • 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-27T21:29:27+00:00Added an answer on May 27, 2026 at 9:29 pm

    I’d write it like this:

    program ProbeClipboard;
    
    {$APPTYPE CONSOLE}
    
    uses
      SysUtils,
      Windows,
      ClipBrd;
    
    var
      CF_GPX: Cardinal;
      ClipboardData: Windows.HGLOBAL;
      Ptr: Pointer;
      Size: DWORD;
    
    begin
      CF_GPX := RegisterClipboardFormat('GPX');
    
      Clipboard.Open;
      try
        if Clipboard.HasFormat(CF_GPX) then
        begin
          Writeln('GPX format available in clipboard');
    
          ClipboardData := Clipboard.GetAsHandle(CF_GPX);
          if ClipboardData=0 then
            RaiseLastOSError;
    
          Ptr := Windows.GlobalLock(ClipboardData);
          if Ptr=nil then
            RaiseLastOSError;
    
          try
            Size := Windows.GlobalSize(ClipboardData);
    
            //Ptr now points to a memory block of Size bytes 
            //containing the clipboard data
          finally
            Windows.GlobalUnlock(ClipboardData);
          end;
        end;
      finally
        Clipboard.Close;
      end;
    end.
    

    Note that I moved the clipboard Open command, which locks the clipboard to be outside the test for the CF_GPX format. That is to avoid a race condition which exists in your code. In your code the clipboard could be modified between the HasFormat call and the OpenClipboard call.

    I also used the Clipboard class exclusively. This class has all you need and you don’t need to use the raw Win32 clipboard API.

    I even put error checking in!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question refers to this prior one posted here on SO by Christian Metzler
I hope that this one is not going to be ask-and-answer question... here goes:
I understand that this question refers to the trivial so I have two tables(one
Well, this question refers directly to windows 7. I run the same code on
This question and answer shows how to send a file as a byte array
This question comes on the heels of the question asked here . The email
Textbox refers to <input type=text> in this question. For each textbox with a given
This question refers to affiliate marketing, but really is a generic question about intercepting
This is more of a computer science question than a programming one, but I
This question refers to both the iOS SDK and JS API for Google Analytics.

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.