////////////////////////////////////////////////////////////////////////////////
//
//     
//
////////////////////////////////////////////////////////////////////////////////
unit Step2_API7_3D_1;

interface
uses
  Sysutils, LDefin2D, ksAuto, Libtool, ks3DCOM_TLB, LDefin3D, LTool3D, Windows;

////////////////////////////////////////////////////////////////////////////////

  procedure  LIBRARYENTRY( command: WORD  ); Pascal;
  function   LIBRARYID   : Cardinal;         Pascal;
  function   LoadStr( ID : Integer ) : string;                     //    
  function   LibMessage( str : string; flags : integer ) : Integer;//   
  function   LibMessageByID( strId, flags : Integer ) : Integer;   //   
  procedure  GetNewKompasAPI;
  procedure  CreateLineDimension3D;
  procedure  LineDimension3DNavigation;
  procedure  EditLineDimension3D;
  procedure  RadialDimension3DWork;
  procedure  DiametralDimension3DWork;
  procedure  AngleDimension3DWork;

implementation

uses
  LtDefine,
  ksApi7,
  ksConstTLB,
  forms;

const
  IDS_NODOC       = 200;
  IDS_OBJ1        = 201;
  IDS_PLANE       = 202;
  IDS_NOCREATE    = 203;
  IDS_LINEDIM3D   = 204;
  IDS_LENGTH      = 205;
  IDS_DIMVAL      = 206;
  IDS_NEWPLANE    = 207;
  IDS_DIM         = 208;
  IDS_NOTSETPLANE = 209;
  IDS_NOTDIM      = 210;
  IDS_NOTCIRCLE   = 211;
  IDS_EDIT        = 212;
  IDS_DIMTEXT     = 213;
  IDS_OBJECT1     = 214;
  IDS_OBJECT2     = 215;

var
  newKompasAPI  : IApplication;                                //  Application 7
  doc           : IKompasDocument3D;
  oType         : integer;

//------------------------------------------------------------------------------
// LibraryId
//---
function LIBRARYID: UINT; pascal;
begin
  Result := 100;  // IDR_LIB
end;


//-------------------------------------------------------------------------------
//   
// ---
function GetCurrentDocument : IKompasDocument3D;

var
  kDoc : IKompasDocument;
begin
  Result := nil;

  if ( newKompasAPI <> nil ) then
     //   
     kDoc := newKompasAPI.ActiveDocument;
  Result := kDoc As IKompasDocument3D;

end;


//-------------------------------------------------------------------------------
//    3D
// ---
function GetSymbols3DContainer : ISymbols3DContainer;

var
  part7 : IPart7;
begin
  Result := nil;

  if ( doc <> nil ) then
  begin
    //   
    part7 := doc.TopPart;
		
    if ( part7 <> nil ) then
      //    3D
      Result := part7 As ISymbols3DContainer;

  end;
end;


//------------------------------------------------------------------------------
// LibraryEntry
//---
procedure LIBRARYENTRY( command: WORD ); pascal;

var
  mes : WideString;
begin
  Application.Handle := GetHWindow;
  GetNewKompasAPI;
  doc := GetCurrentDocument;

  if ( doc <> nil ) then
  begin
    case command of
       1: CreateLineDimension3D;
       2: LineDimension3DNavigation;
       3: EditLineDimension3D;
       4: RadialDimension3DWork;
       5: DiametralDimension3DWork;
       6: AngleDimension3DWork;
    end;
    newKompasAPI := nil;
  end
  else
  begin
    mes := LoadStr( IDS_NODOC );
    ksMessageW( PWideChar(mes) );
  end;
end;


//-------------------------------------------------------------------------------
//     API
// ---
procedure GetNewKompasAPI;
var
  disp : IDispatch;
begin
	if newKompasAPI = nil then
  begin
    disp := IDispatch(CreateKompasApplication);
    newKompasAPI := disp As IApplication;
  end;
end;


//-----------------------------------------------------------------------------
//  
// ---
function UserFilterProc( e : PIEntity ) : Integer; pascal;
 var
   e1 : IEntity;
begin
  e1 := IEntity(e);
  if ( (e1 <> nil) And ((oType = 0) Or (e1.GetType() = oType)) ) then
    Result := 1
  else
    Result := 0;
end;


//-------------------------------------------------------------------------------
//      
// ---
function SetLineDimObjectPlane( dim : ILineDimension3D ) : boolean;

var
  doc3D   : IDocument3D;
  obj1,
  plane   : IEntity;
  mObj1,
  mPlane  : IModelObject;
  mes     : WideString;
begin
	Result := false;
	//   - 
	oType := o3d_edge;

	//    3D  API7  API5
	doc3D := IUnknown( ksTransferInterface(PIUnknown(doc), ksAPI3DCom, 0{ }) ) As IDocument3D;

	if ( doc3D <> nil ) then
	begin
    mes := LoadStr( IDS_OBJ1 );
		//     - 
		obj1 := IEntity( doc3D.UserSelectEntity(nil, @UserFilterProc, PWideChar(mes)) );

		if ( obj1 <> nil ) then
		begin
			//   - 
			oType := o3d_face;
      mes := LoadStr( IDS_PLANE );
			//     - 
			plane := IEntity( doc3D.UserSelectEntity(nil, @UserFilterProc, PWideChar(mes)) );

			if ( plane <> nil ) then
			begin
				//       API5  API7
				mObj1 := IUnknown( ksTransferInterface( PIUnknown(obj1), ksAPI7Dual, 0) ) As IModelObject;
				mPlane :=  IUnknown( ksTransferInterface( PIUnknown(plane), ksAPI7Dual, 0) ) As IModelObject;

				if ( (mObj1 <> nil) And (mPlane <> nil) ) then
				begin
					//     (  
					//    ,     )
					dim.Object1 := mObj1;
					//    
					dim.Plane := mPlane;
					Result := true;
          mObj1._Release;
          mPlane._Release;
				end;
        plane._Release;
			end;
      obj1._Release;
		end;
    doc3D._Release;
	end;
end;


//-------------------------------------------------------------------------------
//    3D
// ---
procedure CreateLineDimension3D;

var
  symbCont  : ISymbols3DContainer;
  dimsCol   : ILineDimensions3D;
  newDim    : ILineDimension3D;
  obj       : IFeature7;
  create    : boolean;
  mes       : WideString;
begin
	//    3D
	symbCont := GetSymbols3DContainer;

	if ( symbCont <> nil ) then
	begin
		//     3D
		dimsCol := symbCont.LineDimensions3D;

		if ( dimsCol <> nil ) then
		begin
			//     3D
			newDim := dimsCol.Add( o3d_lineDimension3D ) As ILineDimension3D;

			if ( newDim <> nil ) then
			begin
				create := false;

				//        
				if ( SetLineDimObjectPlane(newDim) ) then
				begin
					//   
					newDim.Length := 30;
					//  
					create := newDim.Update;
				end

				else
        begin
					//   "  "
          mes := LoadStr( IDS_NOCREATE );
					ksMessageW( PWideChar(mes) );
        end;

				//    , 
				if ( Not(create) ) then
				begin
					obj := newDim As IFeature7;
					
					if ( obj <> nil ) then
						obj.Delete;
				end;
			end;
		end;
	end;
end;


//-------------------------------------------------------------------------------
//       3D
// ---
procedure GetLineDimensionPar( dim : ILineDimension3D );

var
  dimText : IDimensionText;
  lenght  : double;
  val     : double;
  mes     : WideString;
begin
	if ( dim <> nil ) then
	begin
		//   
		lenght := dim.Length;
		val := 0;

		//   
		dimText := dim As IDimensionText;

		if ( dimText <> nil ) then
			val := dimText.NominalValue;

		//  
    mes := LoadStr( IDS_LINEDIM3D );
    mes := mes + #13#10 + LoadStr( IDS_LENGTH ) + FormatFloat( '#.##', lenght );
    mes := mes + #13#10 + LoadStr( IDS_DIMVAL ) + FormatFloat( '#.##', val );
		ksMessageW( PWideChar(mes) );
	end;
end;


//-------------------------------------------------------------------------------
//      3D
// ---
procedure LineDimension3DNavigation;

var
  symbCont  : ISymbols3DContainer;
  doc3D     : IDocument3D;
  selectMng : ISelectionMng;
  dimsCol   : ILineDimensions3D;
  lineDim   : ILineDimension3D;
  dimObj    : IEntity;
  i         : integer;
begin
	if ( doc <> nil ) then
	begin
		//    3D
		symbCont := GetSymbols3DContainer;

		if ( symbCont <> nil ) then
		begin
			//     3D
			dimsCol := symbCont.LineDimensions3D;
			//    3D  API7  API5
			doc3D := IUnknown( ksTransferInterface(PIUnknown(doc), ksAPI3DCom, 0{ }) ) As IDocument3D;

			if ( doc3D <> nil ) then
			begin
				//   
				selectMng := ISelectionMng( doc3D.GetSelectionMng );

				if ( (dimsCol <> nil) And (selectMng <> nil) ) then
				begin
					//   
					for i := 0 to dimsCol.Count-1 do
					begin
						//      
						lineDim := dimsCol.LineDimension3D[i] As ILineDimension3D;

						if ( lineDim <> nil ) then
						begin
							//    3D  API7  API5
              dimObj := IUnknown( ksTransferInterface(PIUnknown(lineDim), ksAPI3DCom, o3d_entity) ) As IEntity;

							if ( dimObj <> nil ) then
							begin
								//  
								selectMng.Select( dimObj );
								//     
								GetLineDimensionPar( lineDim );
								//  
								selectMng.Unselect( dimObj );
							end;
						end;
					end;
				end;
			end;
		end;
	end;
end;


//-------------------------------------------------------------------------------
//    
// ---
function SetNewPlane( dim : ILineDimension3D; doc3D : IDocument3D ) : boolean;

var
  obj1  : IEntity;
  plane : IModelObject;
  mes   : WideString;
begin
	Result := false;

	if ( (dim <> nil) And (doc3D <> nil) ) then
	begin
		oType := o3d_face;
    mes := LoadStr( IDS_NEWPLANE );
		//    
    obj1 := IEntity( doc3D.UserSelectEntity(nil, @UserFilterProc, PWideChar(mes)) );

		if ( obj1 <> nil ) then
		begin
			//     API5  API7
      plane := IUnknown( ksTransferInterface( PIUnknown(obj1), ksAPI7Dual, 0) ) As IModelObject;

			if ( plane <> nil ) then
			begin
				//   
				dim.Plane := plane;
				Result := true;
        plane._Release;
			end;
      obj1._Release;
		end;
	end;
end;


//-------------------------------------------------------------------------------
//     3D
// ---
procedure ChangeLineDimensionPar( dim : ILineDimension3D );

var
  dimPars : IDimensionParams;
begin
	if ( dim <> nil ) then
	begin
		//    
		dimPars := dim As IDimensionParams;

		if ( dimPars <> nil ) then
		begin
			//   - 
			dimPars.ArrowType1 := ksNotch;
			dimPars.ArrowType2 := ksNotch;
			//   - 
			dimPars.ArrowPos := ksDimArrowOutside;
			//   - 
			dimPars.ShelfDirection := ksLSRight;
			//  
			dimPars.ShelfLength := 10;
			//   
			dimPars.ShelfAngle := 45;
		end;
	end;
end;


//-------------------------------------------------------------------------------
//    3D
// ---
procedure EditLineDimension3D;

var
  doc3D   : IDocument3D;
  obj1    : IEntity;
  mObj1   : IModelObject;
  lineDim : ILineDimension3D;
  mes     : WideString;
begin
	if ( doc <> nil ) then
	begin
		//    3D  API7  API5
    doc3D := IUnknown( ksTransferInterface(PIUnknown(doc), ksAPI3DCom, 0{ }) ) As IDocument3D;

		if ( doc3D <> nil ) then
		begin
			oType := o3d_entity;
      mes := LoadStr( IDS_DIM );
			//    
      obj1 := IEntity( doc3D.UserSelectEntity(nil, nil, PWideChar(mes)) );

			if ( obj1 <> nil ) then
			begin
				//     API5  API7
        mObj1 := IUnknown( ksTransferInterface( PIUnknown(obj1), ksAPI7Dual, 0) ) As IModelObject;

				if ( (mObj1 <> nil) And ( mObj1.ModelObjectType = o3d_lineDimension3D) ) then
				begin
					//     3D
					lineDim := mObj1 As ILineDimension3D;

					if ( lineDim <> nil ) then
					begin
						//    
						if ( Not(SetNewPlane(lineDim, doc3D)) ) then
            begin
							//   "     "
              mes := LoadStr( IDS_NOTSETPLANE );
							ksMessageW( PWideChar(mes) );
            end;

						//   
						ChangeLineDimensionPar( lineDim );
						//   
						lineDim.Length := lineDim.Length - 10;
						//  
						lineDim.Update;
					end;
          mObj1._Release;
				end
				else
        begin
					//   "    "
          mes := LoadStr( IDS_NOTDIM );
					ksMessageW( PWideChar(mes) );
        end;
        obj1._Release;
			end;
      doc3D._Release;
		end;
	end;
end;


//-------------------------------------------------------------------------------
//    3D
// ---
function CreateRadDimension3D( dim : IRadialDimension3D ) : boolean;

var
  doc3D   : IDocument3D;
  edge    : IEntity;
  edgeDef : IEdgeDefinition;
  mObj1   : IModelObject;
  dimPars : IDimensionParams;
  mes     : WideString;
begin
	Result := false;

	if ( dim <> nil ) then
	begin
		//    3D  API7  API5
		doc3D := IUnknown( ksTransferInterface(PIUnknown(doc), ksAPI3DCom, 0{ }) ) As IDocument3D;

		if ( doc3D <> nil ) then
		begin
			oType := o3d_edge;
      mes := LoadStr( IDS_OBJ1 );
			//     - 
      edge := IEntity( doc3D.UserSelectEntity(nil, @UserFilterProc, PWideChar(mes)) );

			if ( edge <> nil ) then
			begin
				//    
				edgeDef := IEdgeDefinition( edge.GetDefinition() );

				// ,    
				if ( (edgeDef <> nil) And (edgeDef.IsCircle <> 0) ) then
				begin
					//     API5  API7
          mObj1 := IUnknown( ksTransferInterface( PIUnknown(edge), ksAPI7Dual, 0) ) As IModelObject;

					if ( mObj1 <> nil ) then
						//  
						dim.Object1 := mObj1;

					//    
					dimPars := dim As IDimensionParams;

					if ( dimPars <> nil ) then
					begin
						//   - 
						dimPars.ShelfDirection := ksLSLeft;
						//  
						dimPars.ShelfLength := 15;
						//   
						dimPars.ShelfAngle := 30;
					end;

					//   -   
					dim.DimensionType := FALSE;
					//  
					dim.Update;
					Result := true;
          edgeDef._Release;
				end
				else
        begin
					//   "   "
          mes := LoadStr( IDS_NOTCIRCLE );
					ksMessageW( PWideChar(mes) );
        end;
        edge._Release;
			end;
      doc3D._Release;
		end;
	end;
end;


//-------------------------------------------------------------------------------
//    3D
// ---
procedure EditRadDimension3D( dim : IRadialDimension3D );

var
  dimPars : IDimensionParams;
  dimText : IDimensionText;
  lowDev  : ITextLine;
begin
	if ( dim <> nil ) then
	begin
		//   -  
		dim.DimensionType := TRUE;

		//    
		dimPars := dim As IDimensionParams;

		if ( dimPars <> nil ) then
			//  
			dimPars.ShelfDirection := ksLSNone;

		//    
		dimText := dim As IDimensionText;

		if ( dimText <> nil ) then
		begin
			//  
			dimText.Tolerance := 'h6';

			//  
			dimText.ToleranceOn := true;

			//     
			lowDev := dimText.LowDeviation;

			//   
			if ( lowDev <> nil ) then
				lowDev.Str := '+0.021';
		end;
		//  
		dim.Update;
	end;
end;


//-------------------------------------------------------------------------------
//      3D
// ---
procedure RadialDimension3DWork;

var
  symbCont  : ISymbols3DContainer;
  dimsCol   : IRadialDimensions3D;
  newDim,
  radDim    : IRadialDimension3D;
  feature   : IFeature7;
  name,
  mes       : WideString;
begin
	//    3D
	symbCont := GetSymbols3DContainer;

	if ( symbCont <> nil ) then
	begin
		//     3D
		dimsCol := symbCont.RadialDimensions3D;

		if ( dimsCol <> nil ) then
		begin
			//     3D
			newDim := dimsCol.Add;

			if ( newDim <> nil ) then
			begin
				//    3D
				if ( CreateRadDimension3D(newDim) ) then
				begin
					name := '';
					//     
					feature := newDim As IFeature7;

					//   
					if ( feature <> nil ) then
						name := feature.Name;

          mes := LoadStr( IDS_EDIT );
					if ( YesNoW(PWideChar(mes)) = 1 ) then
					begin
						//      
						radDim := dimsCol.RadialDimension3D[name];
						//  
						EditRadDimension3D( radDim );
					end;
				end
				else
        begin
					//   "  "
          mes := LoadStr( IDS_NOCREATE );
					ksMessageW( PWideChar(mes) );
        end;
			end;
		end;
	end;
end;


//-------------------------------------------------------------------------------
//   
// ---
function CreateDiamDimension3D( dim : IDiametralDimension3D ) : boolean;

var
  doc3D   : IDocument3D;
  edge    : IEntity;
  edgeDef : IEdgeDefinition;
  mObj1   : IModelObject;
  mes     : WideString;
begin
	Result := false;

	if ( dim <> nil ) then
	begin
		//    3D  API7  API5
		doc3D := IUnknown( ksTransferInterface(PIUnknown(doc), ksAPI3DCom, 0{ }) ) As IDocument3D;

		if ( doc3D <> nil ) then
		begin
			oType := o3d_edge;
      mes := LoadStr( IDS_OBJ1 );
			//     - 
      edge := IEntity( doc3D.UserSelectEntity(nil, @UserFilterProc, PWideChar(mes)) );

			if ( edge <> nil ) then
			begin
				//    
				edgeDef := IEdgeDefinition( edge.GetDefinition() );

				// ,    
				if ( (edgeDef <> nil) And (edgeDef.IsCircle <> 0) ) then
				begin
					//     API5  API7
          mObj1 := IUnknown( ksTransferInterface( PIUnknown(edge), ksAPI7Dual, 0) ) As IModelObject;

					if ( mObj1 <> nil ) then
						//  
						dim.Object1 := mObj1;

					//  
					dim.Update;
					Result := true;
          edgeDef._Release;
				end
				else
        begin
					//   "   "
          mes := LoadStr( IDS_NOTCIRCLE );
					ksMessageW( PWideChar(mes) );
        end;
        edge._Release;
			end;
      doc3D._Release;
		end;
	end;
end;


//-------------------------------------------------------------------------------
//   
// ---
procedure EditDiamDimension3D( dim : IDiametralDimension3D );

var
  dimText   : IDimensionText;
  txtUnder  : IText;
begin
	if ( dim <> nil ) then
	begin
		//   -  
		dim.DimensionType := True;

		//    
		dimText := dim As IDimensionText;

		if ( dimText <> nil ) then
		begin
			//      
			txtUnder := dimText.TextUnder;

			//   
			if ( txtUnder <> nil ) then
				txtUnder.Str := LoadStr( IDS_DIMTEXT );

			//  
			dimText.Underline := TRUE;
		end;
		//  
		dim.Update;
	end;
end;


//-------------------------------------------------------------------------------
//      3D
// ---
procedure DiametralDimension3DWork;
var
  symbCont  : ISymbols3DContainer;
  dimsCol   : IDiametralDimensions3D;
  newDim,
  diamDim   : IDiametralDimension3D;
  feature   : IFeature7;
  name,
  mes       : WideString;
begin
	//    3D
	symbCont := GetSymbols3DContainer;

	if ( symbCont <> nil ) then
	begin
		//     3D
		dimsCol := symbCont.DiametralDimensions3D;

		if ( dimsCol <> nil ) then
		begin
			//     3D
			newDim := dimsCol.Add;

			if ( newDim <> nil ) then
			begin
				//    3D
				if ( CreateDiamDimension3D(newDim) ) then
				begin
					name := '';
					//     
					feature := newDim As IFeature7;

					//   
					if ( feature <> nil ) then
						name := feature.Name;

          mes := LoadStr( IDS_EDIT );
					if ( YesNoW(PWideChar(mes)) = 1 ) then
					begin
						//      
						diamDim := dimsCol.DiametralDimension3D[name];
						//  
						EditDiamDimension3D( diamDim );
					end;
				end
				else
        begin
					//   "  "
          mes := LoadStr( IDS_NOCREATE );
					ksMessageW( PWideChar(mes) );
        end;
			end;
		end;
	end;
end;


//-------------------------------------------------------------------------------
//    3D
// ---
function CreateAngleDimension3D( dim : IAngleDimension3D ) : boolean;

var
  doc3D : IDocument3D;
  obj1,
  obj2  : IEntity;
  mObj1,
  mObj2 : IModelObject;
  mes   : WideString;
begin
	Result := False;

	if ( (dim <> nil) And (doc <> nil) ) then
	begin
		//    3D  API7  API5
    doc3D := IUnknown( ksTransferInterface(PIUnknown(doc), ksAPI3DCom, 0{ }) ) As IDocument3D;

		if ( doc3D <> nil ) then
		begin
      mes := LoadStr( IDS_OBJECT1 );
			//    1- 
      obj1 := IEntity( doc3D.UserSelectEntity(nil, nil, PWideChar(mes)) );
      mes := LoadStr( IDS_OBJECT2 );
			//    2- 
      obj2 := IEntity( doc3D.UserSelectEntity(nil, nil, PWideChar(mes)) );

			if ( (obj1 <> nil) And (obj2 <> nil) ) then
			begin
				//     API5  API7
        mObj1 := IUnknown( ksTransferInterface( PIUnknown(obj1), ksAPI7Dual, 0) ) As IModelObject;
        mObj2 := IUnknown( ksTransferInterface( PIUnknown(obj2), ksAPI7Dual, 0) ) As IModelObject;

				if ( (mObj1 <> nil) And (mObj2 <> nil) ) then
				begin
					// 1- 
					dim.Object1 := mObj1;
					// 2- 
					dim.Object2 := mObj2;
					//   
					dim.Length := 20;
					//  
					dim.Update;
					Result := True;
				end;
			end;
		end;
	end;
end;


//-------------------------------------------------------------------------------
//    3D
// ---
procedure EditAngleDimension3D( dim : IAngleDimension3D );

var
  dimPars : IDimensionParams;
  dimText : IDimensionText;
begin
	if ( dim <> nil ) then
	begin
		//   -   () 
		dim.DimensionType := ksADMaxAngle;
		//    
		dim.Length := dim.Length + 10;

		//    
		dimPars := dim As IDimensionParams;

		if ( dimPars <> nil ) then
			//    - ,   
			dimPars.TextOnLine := ksDimTextParallelInCut;

		//    
		dimText := dim As IDimensionText;

		if ( dimText <> nil ) then
			//      
			dimText.TextFormat := ksDimTextFormatGDD;

		//  
		dim.Update;
	end;
end;


//-------------------------------------------------------------------------------
//      3D
// ---
procedure AngleDimension3DWork;
var
  symbCont  : ISymbols3DContainer;
  dimsCol   : IAngleDimensions3D;
  newDim,
  angDim    : IAngleDimension3D;
  feature   : IFeature7;
  name,
  mes       : WideString;
begin
	//    3D
	symbCont := GetSymbols3DContainer;

	if ( symbCont <> nil ) then
	begin
		//     3D
		dimsCol := symbCont.AngleDimensions3D;

		if ( dimsCol <> nil ) then
		begin
			//     3D
			newDim := dimsCol.Add;

			if ( newDim <> nil ) then
			begin
				//    3D
				if ( CreateAngleDimension3D(newDim) ) then
				begin
					name := '';
					//     
					feature := newDim As IFeature7;

					//   
					if ( feature <> nil ) then
						name := feature.Name;

          mes := LoadStr( IDS_EDIT );
					if ( YesNoW(PWideChar(mes)) = 1 ) then
					begin
						//      
						angDim := dimsCol.AngleDimension3D[name];
						//  
						EditAngleDimension3D( angDim );
					end;
				end
				else
        begin
					//   "  "
          mes := LoadStr( IDS_NOCREATE );
					ksMessageW( PWideChar(mes) );
        end;
			end;
		end;
	end;
end;


//----------------------------------------------------------------------------------------------
//    
//---
function LoadStr( ID : Integer ) : string;
var
  buf : array [0..255] of char;
begin
  ksConvertLangStrEx( hInstance, ID, buf, 255 );
  Result := buf;
end;


//------------------------------------------------------------------------------
//  
// ---
function LibMessage( str : string; flags : integer ) : Integer;
var
 enabse : Integer;
begin
  enabse := IsEnableTaskAccess();  //  
  if enabse <> 0 then             //     
    EnableTaskAccess(0);          //  

    //                                      
  Result := Application.MessageBox( PChar(str), PChar(LoadStr(LIBRARYID)), flags );

  if enabse <> 0 then                         //      
    EnableTaskAccess(1);              //    

end;


//------------------------------------------------------------------------------
//  
// ---
function LibMessageByID( strId, flags : Integer ) : Integer;
begin
  Result := LibMessage( LoadStr(strId), flags );
end;

end.


