Solved

Problem changing from Strings to Array

Posted on 2000-04-28
6
151 Views
Last Modified: 2010-04-04
I am getting  data from an Access database. Two Fields 'Servers' and 'Drives'.  I then want to Select the first Server and the FIRST drive Letter ( then I will go back and get the second drive Letter)  I want to take the Server Name and Drive letter to make a Network Connection.  The trouble I am having is when I try to add the strings to the array?  I then get the incompatable types sting and Pchar.  Any input on how to get the database information into the WNetAddConection?

Here is how I get the Information from the database
procedure TForm1.Button1Click(Sender: TObject);
var
   DriverArray : Array[0..8] of char;

begin
          if Table1.FieldByName ('drives').AsString<> '' then
          begin
          S := Table1.FieldByName ('ServerName').AsString+ ' ';
          D := Table1.FieldByName ('drives').AsString;
          DBServerList.Items.Add(S);
          {Move(D[1], DriverArray,Length(D));
          Memo1.Lines.Append(DriverArray[1]);}
          end;

//LOOP THRU the DRIVES

procedure TForm1.Button2Click(Sender: TObject);
var
   MyArray : array[0..10] of char;
   y : integer;
begin
     Move(D[1], MyArray, Length(D));
     y:= 0;
     WHile (MyArray[y] <> #0) do
           begin
               ListBox1.Items.Add(MyArray[y]);
               Memo1.Lines.Add(MyArray[y]);
               y:= y+1;
           end;

end;

procedure TForm1.Button3Click(Sender: TObject);
begin
     Table1.Next;
     Memo1.Lines.Clear;
end;


HERE IS WHERE THE PROBLEMS START!!!!

procedure TForm1.Button4Click(Sender: TObject);
var
   NR : TNetResource;
   NetArray : String;
   //NetArray : array [0..15] of char;
   x : integer;
begin
    // NetArray := '\\CEC-A\C$';
     NetArray := '\\' + S + '\' + D + '$';// NEEDS TO BE ENTERED LIKE THIS
     FillChar(NR, SizeOf(NR),0);
     NR.dwType := RESOURCETYPE_DISK;
     NR.lpLocalName := 'E:';
     NR.lpRemoteName := NetArray;
     WNetAddConnection2 (NR, nil, nil, 0);

end;


IF I assign the entire Servername and drive to the array the connections occur.  I am trying to get this so the connections and disconnects occur automaticly.  While the connections are made I get the Drive SIze and Free Space.
0
Comment
Question by:msmouse
6 Comments
 
LVL 10

Accepted Solution

by:
Lischke earned 50 total points
Comment Utility
Hi,

you obviously have not yet understood the concept of String, PChar, array of char etc. so let me explain that a bit.

Usually Delhi stores its strings in the data type String which is nothing more than a piece of memory. A Delphi string is reference counted and always ends with a 0 byte to make it compatible to a PChar. So all you have to do to pass a PChar made from a String is to assign:

var
  ServerName: String;

NR.lpRemoteName := PChar(ServerName);

Using a string as intermediate storage frees you from taking care about memory allocation etc. Note: You can even mix variables and literals and still cast them to a PChar without any time penalty, like:

  NR.lpRemoteName := PChar(Server + '\D$');

Ciao, Mike
0
 
LVL 1

Author Comment

by:msmouse
Comment Utility
You are correct with the my understanding of Pchar's.  This is my first program using Delphi so I have not yet figured out PChar's.  And I only have limited experence using strings and array's.  I will try your suggestion later, it's time for me to get out of here.

Thanks
0
 
LVL 1

Expert Comment

by:AttarSoftware
Comment Utility
Or, you can use:

  StrPCopy( NetArray, '\\' + S + '\' + D + '$' ) ;

To do the same thing without casting...

Tim.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Expert Comment

by:bryan7
Comment Utility
listenning
0
 
LVL 10

Expert Comment

by:Lischke
Comment Utility
msmouse, have you had success?
0
 
LVL 1

Author Comment

by:msmouse
Comment Utility
StrPCopy also works, I'll have to decide which way will work the best.  Thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now