We help IT Professionals succeed at work.

EM_STREAMIN -- Win2k vs. Win9x

millerw
millerw asked
on
Start with a form with only a TRichEdit on it named RichEdit1 by default.  I have it set to alClient alignment.  Add "RichEdit" to the uses clause then paste the following code in:

function RTFStreamInCallback(PStream: LongInt; ABuffer: PByte; Count: LongInt;
 var ActualCount: LongInt): LongInt; stdcall;
var
 Available: Integer;
begin
 with TStream(PStream) do
 begin
   Available := Size - Position;
   Result := 0;
   if Available <= Count then
   begin
     ActualCount := Read(ABuffer^, Available);
     if ActualCount <> Available then
       Result := E_FAIL;
   end
   else
   begin
     ActualCount := Read(ABuffer^, Count);
     if ActualCount <> Count then
       Result := E_FAIL;
   end;
 end;
end;

function RTFStreamOutCallback(PStream: LongInt; ABuffer: PByte; Count: LongInt;
 var ActualCount: LongInt): LongInt; stdcall;
begin
 with TStream(PStream) do
 begin
   if Count > 0 then
     ActualCount := Write(ABuffer^, Count);
   Result := 0;
 end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  AStrStream: TStringStream;
  AEditStream: TEditStream;
begin
  RichEdit1.Clear;
  AStrStream := TStringStream.Create(
    '{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Times New Roman;}}' + #13 + #10 +
    '\viewkind4\uc1\pard\tx1080\tx2160\tx3420\tx4860\f0\fs18 %s\tab %s\tab %s\tab %s\tab %s %s %s %s\par' + #13 + #10 +
    '\par' + #13 + #10 +
    '\par' + #13 + #10 +
    '}');
  try
    with AEditStream do
    begin
      dwCookie := LongInt(AStrStream);
      dwError:=0;
      pfnCallback:=RTFStreamInCallback;
    end;
    SendMessage(RichEdit1.Handle, EM_STREAMIN, SF_RTF or SFF_SELECTION, LongInt(@AEditStream));

    RichEdit1.SelStart := MaxInt;

    AStrStream.Position := 0;

    SendMessage(RichEdit1.Handle, EM_STREAMIN, SF_RTF or SFF_SELECTION, LongInt(@AEditStream));

    RichEdit1.SelStart := MaxInt;

    AStrStream.Position := 0;

    SendMessage(RichEdit1.Handle, EM_STREAMIN, SF_RTF or SFF_SELECTION, LongInt(@AEditStream));

    RichEdit1.SelStart := MaxInt;

    ShowMessage(IntToStr(RichEdit1.Lines.Count));
  finally
    AStrStream.Free;
  end;
end;

Now run the code on Windows 2000 (count = 9) and then on Windows 9x (count = 6).  If you get something different, LET ME KNOW!!!!!

The questions are:  Why does Windows 9x act differently than Windows 2000?  Is there a way to make the two act the exact same way?  I *think* the problem is with the version of the riched20.dll file.  Where can I download an upgrade for Windows 9x to upgrade all my machines to the same version so that they all act the same way?  Or am I going to have to write conditional code so that both operating systems generate the same letters even though they don't run the exact same code.  Additionally, according to the Microsoft web side Rich Edit v4.0 doesn't exist, but I have a riched20.dll file that contains Rich Edit v4.0 on my machine that was installed by Office XP.

Scott
Comment
Watch Question

Author

Commented:
NOTE:  Some of the code may be unnecessary in the current situation.  The reason it is there is because I've been trying various situations with and without the SFF_SELECTION on the first EM_STREAMIN and the code is necessary in that occurance to reposition the cursor to the end for subsequent streaming.
BRONZE EXPERT
Top Expert 2004

Commented:
courious  . . . listening . . .

Author

Commented:
For those listening, the only solution so far has been to use a hidden RTF, in addition to the actual one, and paste the selection into that one using only SF_RTF.  Position the cursor to the end and memorize the position.  Obtain the current position of the cursor in the real RTF control and add those two together to get the "needed" cursor position.  Then do the paste using "SF_RTF or SFF_SELECTION" and set the cursor to the calculated desired position.  Select to the end of the document from new position and erase the selection.

Sounds convoluted, I know, but it works.

Scott
I am unclear what you'd like done with this question, since it remains open today.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20176871.html
http://www.experts-exchange.com/questions/Q.20270793.html
http://www.experts-exchange.com/questions/Q.20292366.html



*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @14 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thanks everyone.
Moondancer
Moderator @ Experts Exchange

Author

Commented:
"Close the question if the information was not useful to you, but may help others. You must tell the
participants why you wish to do this, and allow for Expert response.  This choice will include a refund
to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information
outside this question thread, please add it."

I presume you have to do this since I do not have this option to invoke.

Scott
Perfect, Scott, thanks.

100 points have been refunded to you for this question, and it has been moved to our PAQ at zero points and closed.  Thanks for adding your workaround, which can help others.

:) Moondancer - EE Moderator

Explore More ContentExplore courses, solutions, and other research materials related to this topic.