?
Solved

Problem changing from Strings to Array

Posted on 2000-04-28
6
Medium Priority
?
157 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
[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
6 Comments
 
LVL 10

Accepted Solution

by:
Lischke earned 200 total points
ID: 2758846
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
ID: 2758918
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
ID: 2759543
Or, you can use:

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

To do the same thing without casting...

Tim.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Expert Comment

by:bryan7
ID: 2763067
listenning
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2768600
msmouse, have you had success?
0
 
LVL 1

Author Comment

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

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