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 1085191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:39:31+00:00 2026-05-16T22:39:31+00:00

SOLUTION BELOW I’ve been looking all over the net to find a solution for

  • 0

SOLUTION BELOW

I’ve been looking all over the net to find a solution for this, but it seems quite hard to get an answer for this in Delphi…

Skip this if you’re familiar with Outlook

Some explanation before:
The Contacts Folder in Outlook is organized like a foldertree in Windows. The Contacts are stored in the Contacts Folder itself or within subfolders.

My Code does add Contacts from an external Database into the Outlook contacts Database. To prevent double entries the programm is supposed to check all contacts and see if it can find an ‘older’ version of the contact entry and update it, or if not, create a new one.
Therefore I wrote a recursion which loops through the folders and checks the contacts.

Within a folder you can get the subfolder by (besides Next, Previous and Last)

Contacts:= Contacts.Folders.Getfirst

//The now selected Folder is the first subfolder within the previous selected one

If I am trying to get any property of this Subfolder like ‘Items.Count’ or anything else, an error occurs because this folder doesn’t exist.
Therefore I want to check if the Folder exists or not, and skip to loop through this subfolder because otherwise the loop would break here and the program stops.

Skip until here if you’re familiar with Outlook workings
THE PROBLEM:

In Debugger this Contacts/Folder Variable (an OleVariant, Pointer to the now selected Folder) contains values similar to this: ‘$0074974C’.
If there is no subfolder this value returns ‘$00000000’. This seems to be a pointer.

How should I check if a folder exists or not?

const
  olFolderContacts = $0000000A;
var
  outlook, NameSpace, Contact, ContactsRoot, Contacts: OleVariant;

begin
Outlook := CreateOleObject('Outlook.Application');
NameSpace := Outlook.GetNameSpace('MAPI');
ContactsRoot := NameSpace.GetDefaultFolder(olFolderContacts);
Contacts:= ContactsRoot;
//We're now in the Contacts Folder
Contacts:= Contacts.folders.getfirst;
//First Subfolder

What didn’t work:
Check if

Contacts = ‘$00000000’ (As string)

Contacts = ‘$00000000’ (As OleVariant)

var
val:TVarRec;
code:
val:=Contacts;
string(Contacts.VWideChar) = ‘$00000000’

var
vntNothing: OLEVariant;
code:
TVarData(vntNothing).VType := varDispatch;
TVarData(vntNothing).VDispatch := Nil;
Contacts = vntNothing

Contacts = unassigned
…
…

In VBA this problem has a simple solution

if Contacts = Nothing

But there is no ‘Nothing’ in Delphi…

Ideas?

  • 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-16T22:39:32+00:00Added an answer on May 16, 2026 at 10:39 pm

    You could first check the count on the Folders collection:

    if Contacts.Folders.Count = 0 then
    

    or

    Contacts := Contacts.Folders.GetFirst;
    if VarIsClear(Contacts) then
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: solved, look below for my solution. first of all, this is my very
This question have been answered. I recommend sumit_programmers solution below. For now, I've removed
I tried the solution below but I don't like it. I am looking for
Problem solved. Solution below. It's been long since I tried to do this in
I thought of solution below because the collection is very very small. But what
I came with below solution but I believe that must be nicer one out
Premise This problem has a known solution (shown below actually), I'm just wondering if
(I have researched this question extensively but not found an adequate solution yet.) I
The solution below compiles but it is not what I want. I would like
I've been a .NET developer for several years now and this is still one

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.