Solved

MSProject98 COM

Posted on 1998-12-09
9
476 Views
Last Modified: 2010-04-04
I have a problem accessing the Tasks in a MSProject98 through the COM interface (msprj98.olb). I can access the property alrite but when I need to get detailed information about the Tasks I get a OLEAUT32.DLL access violation
0
Comment
Question by:jerboa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 1350045
I don't now the MSProject98 com interface. But if you post some code here, perhaps I'll find a bug in your sources...

Regards, Madshi.
0
 

Author Comment

by:jerboa
ID: 1350046
{Import the 'msprj8.olb' type library to compile}
type
 TProject98 = class  
   private
     FProject98: _MsProject;

constructor TProject98.Create;
begin
  FProject98 := CoApplication_.Create;
end;

function TProject98.GetNumberOfTasks: Integer;
begin
  {This Code crashes}
  Result := FProject98.ActiveProject.Tasks.Count;
end;

function TProject98.GetTasks: integer;
var
  oTasks: Tasks;
begin
  oTasks := FProject98.ActiveProject.Tasks; {This works}
  Result := oTasks.Count; {This crashes too}
end;

0
 

Author Comment

by:jerboa
ID: 1350047
{Import the 'msprj8.olb' type library to compile}
type
 TProject98 = class  
   private
     FProject98: _MsProject;

constructor TProject98.Create;
begin
  FProject98 := CoApplication_.Create;
end;

function TProject98.GetNumberOfTasks: Integer;
begin
  {This Code crashes}
  Result := FProject98.ActiveProject.Tasks.Count;
end;

function TProject98.GetTasks: integer;
var
  oTasks: Tasks;
begin
  oTasks := FProject98.ActiveProject.Tasks; {This works}
  Result := oTasks.Count; {This crashes too}
end;

0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 44

Expert Comment

by:bruintje
ID: 1350048
Hi Jerboa,

Had an evaluation version somewhere on my disk, so did the install to get to the typelib. If the code above is all you have so far then I will explain the errors.

crash 1 is because you have no Activeproject open
crash 2 same reason.

This will get you on your way

procedure TForm1.Button1Click(Sender: TObject);
var
  aProject: OleVariant;
  CurrentTasks: Integer;
begin
  aProject := CreateOleObject('MSProject.Application');
  aProject.Visible := True;
  try
    aProject.FileNew;
    CurrentTasks := aProject.ActiveProject.NumberOfTasks;
    Showmessage(IntToStr(CurrentTasks));
  except
    aProject.Free;//project doesn't support free but the object will be released in case of trouble
  end;
end;


But the beauty (and the trouble) is that all this MS stuff is going through OleVariants. So before you can acces the information you would like to see, you have to create an instance of the application and put it into an Olevariant.
Then you have to go through the object model of Project to acces what you want to have.

If you have any questions about this ask them.
br(UINT)je.
0
 

Author Comment

by:jerboa
ID: 1350049
I had an active project open and the NumOfTasks property worked fine but I need to get the more detailed info that the Tasks interface provides. NumOfTasks is a property of the ActiveProject (works fine in my code too) but I need some code to access the names of each tasks (Name is a property of the Task interface), I get an error whenever I try to access any property of the Tasks interface:

procedure TProject98.GetTaskNames;
var
  oTasks: Tasks;
  FTasks: TStringList;
begin
  FTasks := TStringlist.Create;
  try
    oTasks := FProject98.ActiveProject.Tasks; {This works}
    for iCounter := 1 to FProject98.ActiveProject.NumOfTasks do
      FTasks.Lines.Add := oTasks.Item[iCounter].Name; {This
            code compiles but crashes at runtime}
  finally
     FTasks.Free;
  end;
end;
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1350050
How does the Tasks type look like?
0
 
LVL 44

Accepted Solution

by:
bruintje earned 100 total points
ID: 1350051
Ok. fair enough if you have the olb look good at the structure because I think it's wonderfull stuff to use, made a project form1, button1, listbox1

unit Unit2;
interface

uses
  Windows,
  Messages,
  SysUtils,
  Classes,
  Graphics,
  Controls,
  Forms,
  Dialogs,
  StdCtrls,
  MSPROJECT_TLB,
  ComObj;

type
  TForm1 = class(TForm)
    Button1: TButton;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
  private
    procedure GetTaskNames(fProject: OleVariant);
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  aProject: OleVariant;
begin
  aProject := CreateActiveOleObject('MSProject.Application');
  aProject.Visible := True;
  try
    aProject.FileNew;
    GetTaskNames(aProject);
  except
    aProject.Free; //project doesn't support free but the object will be released.
  end;
end;

procedure TForm1.GetTaskNames(fProject: OleVariant);
var
  FTasks: TStringList;
  iCounter: Integer;
begin
  FTasks := TStringlist.Create;
  try
    for iCounter := 1 to FProject.ActiveProject.NumberOfTasks do begin
      FTasks.Add(FProject.ActiveProject.Tasks.Item[iCounter].Name); {This code compiles but crashes at runtime}
      next;
    end;
    ListBox1.Items := FTasks;
  finally
    FTasks.Free;
  end;
end;

end.

Hope this helps,
BTW Could make a sample that retrieves more then just the name ask for it and I can see what I can brew.

:O)
Bruintje.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 1350052
and of course things will compile just fine I suspect that delphi doesn't check all these OLE properties to good(correct me if I am wrong.)


0
 

Author Comment

by:jerboa
ID: 1350053
Thanky Bruintje,

Ik heb de OLE Variable van type verandert
    _MSProject -> OLEVariant en nu kan ik wel aan de Task informatie. Dan verlies ik wel een beetje Early binding functionaliteit omdat de compiler niet echt kan type checken. Maar de code werkt en dat is het belangrijkste...
0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month6 days, 3 hours left to enroll

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question